Enterprise Library 2.0 logging problem

Topics: Logging Application Block
Nov 16, 2007 at 9:29 AM
Hi, im newbie wit Enterprise Library and triying to test the logging block.



I have a simple windows application and i want to log some information to the "Event Log".



Im using :

Logger.Write(SomeInfoString);



when I run the application nothing is logged and i get no errors.

What am i missing ???



Heres the app.config section for the logging:





<configSections>

<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />

</configSections>

<loggingConfiguration name="Logging Application Block" tracingEnabled="false"

defaultCategory="" logWarningsWhenNoCategoriesMatch="false">

<listeners>

<add source="Enterprise Library Logging" formatter="Text Formatter"

log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"

traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"

name="Formatted EventLog TraceListener" />

</listeners>

<formatters>

<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;)}{message}"

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"

name="Text Formatter" />

</formatters>

<categorySources>

<add switchValue="Information" name="Category" />

</categorySources>

<specialSources>

<allEvents switchValue="All" name="All Events" />

<notProcessed switchValue="All" name="Unprocessed Category" />

<errors switchValue="All" name="Logging Errors & Warnings" />

</specialSources>

</loggingConfiguration>

<appSettings>

........





Thanks in advance

Tok
Nov 16, 2007 at 12:53 PM
Tok,

You haven't linked your event log trace listener to any source.

Look at the help topics describing the overall design of the block (ms-help://ms.EntLib.2007May/EnterpriseLibrary/html/06-150-Design_of_the_Logging_Application_Block.htm) for background information. Unfortunately, the topic on configuration is missing the description on how to specify category sources; you need to add a new category on the Category Sources, and add a trace listener reference to it pointing to your event log trace listener.

Regards,
Fernando
Nov 16, 2007 at 2:28 PM
Thanks alot Fernando.
You made atleast one person happy for one day :-)