Is it possible to set the Event Viewer category when logging?

Topics: Logging Application Block
Mar 13, 2008 at 4:12 PM
I am using the May 31st, 2007 Enterprise Library for logging. When I look at the logged information in windows Event Viewer, the category has a value of NONE. I would like to specify the value for category. Is that possible? There is a lot of documentation about categories, but it seems that the documentation about categories (like the categories property) does not map to the category column in event viewer.

Here is my example:
Logger.Write("Connected to: " + dbConnString, "SQL", 1, 102, System.Diagnostics.TraceEventType.Information);

Here is partial info in my Event Viewer log (the Category of SQL is NOT the category column):
Timestamp: 3/13/2008 3:05:30 PM
Message: Connected to: Data Source=GBAMS-DEV-01\DEV;Initial Catalog=GBAStretDev;User ID=GBA_USER;Passwordsuppressed
Category: SQL
Priority: 1
EventId: 102
Severity: Information

My Config is like this:
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<add source="My App Name" formatter="Text Formatter" log="Application"
machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Formatted EventLog TraceListener" />
<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Text Formatter" />
<add switchValue="Off" name="SQL">
<add name="Formatted EventLog TraceListener" />
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<add name="Formatted EventLog TraceListener" />
Mar 21, 2008 at 3:27 PM
Hi Rob,

Short answer: no by default.

LAB's categories and the EventLog's categories are quite different. In particular, the EventLog's categories are source specific and are specified by using standard Windows message tables in unmanaged dlls. So, in order to provide categories from a managed application you still need to author the message table, compile and link it into a dll, install an EventLog source specifying this dll as the category messages file and, when you raise an event from your app, configure the new entry with the installed source name and a category id that maps to the message table; you can get the details in and

The EventLog trace listeners in the LAB do not take advantage of this capability, but new trace listeners can be created to take advantage of it.

Mar 22, 2008 at 12:54 AM
Thanks for the info Fernando.