Setting a "category" in the .net corporate library journal (in the event log)

I write several logs to the event log using the Microsoft corporate library

His recordings are excellent, but don't seem to set a category in the event log. The category looks fine in the body of the log message (if I decided to install this), but the event viewer does not receive the category.

What am I missing?


C # source

LogEntry log = new LogEntry(); log.Message = "Test"; log.Categories.Add("Event"); Logger.Write(log); 

web configuration

 <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true"> <listeners> <add source="TestLogSource" formatter="Text Formatter" log="TestLog" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Formatted EventLog TraceListener" /> </listeners> <formatters> <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Severity: {severity}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Text Formatter" /> </formatters> <categorySources> <add switchValue="All" name="Events"> <listeners> <add name="Formatted EventLog TraceListener" /> </listeners> </add> <add switchValue="All" name="General"> <listeners> <add name="Formatted EventLog TraceListener" /> </listeners> </add> </categorySources> <specialSources> <allEvents switchValue="All" name="All Events" /> <notProcessed switchValue="All" name="Unprocessed Category" /> <errors switchValue="All" name="Logging Errors &amp; Warnings"> <listeners> <add name="Formatted EventLog TraceListener" /> </listeners> </errors> </specialSources> 

+6
c # logging enterprise-library
source share
2 answers

The EventLog category is separate and distinct from the LogEntry categories. Therefore, I do not think that you can use LogEntry categories to display in the Category EventLog field.

In terms of data, the types are incompatible: the EventLog category is short, and the LogEntry category is a string. Yes, a line is displayed in the event viewer, but this value is viewed using the CategoryMessageFile parameter defined in the registry.

If you want to do some filtering in the event viewer, you can use the LogEntry.EventId property. You can fill it out using any agreement. for example, unique event identifiers for each logging point, event identifier for each level, event identifier for each class, or other convention.

As a backup, you can always find Search for your category in the description of the EventLog entry.

+5
source share

This link (http://drdobbs.com/184405714) provides more information on how to create a category.

+1
source share

All Articles