Enterprise library not logging severity correctly

2019-06-10 01:11发布

问题:

I have a problem with enterprise library 5. It's writing to the event log all the information I want it to write, however, it is not respecting the severity settings I configure.

My exception handling configuration block looks like this:

<exceptionHandlers>
  <add name="Logging Exception Handler"
       type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging...,"
       logCategory="General"
       eventId="10000"
       severity="Critical"
       title="My unknown error"
       formatterType="Micros...ExceptionFormatter, Micros...ExceptionHandling"
       priority="0" />
</exceptionHandlers>

My event log listener template starts with:

Severity: {severity}{newline}

The event log entry is logged as "Error", not "Critical", however the message that is actually logged contains the text "Severity: Critical"

Any pointers as to how I can actually log an exception as Critical without having to actually write my own exception handler/formatter?

回答1:

The behavior you are seeing is part of the .NET API.

There is no level or severity of Critical in the EventLogEntryType Enumeration which is used to log to the EventLog. TraceEventType, which is used by Enterprise Library as well as the .NET tracing infrastructure, does support a Critical severity.

However, inside the System.Diagnostics.EventLogTraceListener, which is used to log to the EventLog, a Critical TraceEventType is converted to an Error EventLogEntryType.

In the Event Viewer there is a filter for Critical but it seems that this level is reserved for low level errors. E.g. kernel related.