Logging does not work for all category sources?

Topics: Logging Application Block
Apr 3, 2007 at 11:51 PM
Hi,

I'm using Logging block from EntLib 2.0. I have created 4 category sources: Audit, Debug, Error, Exception using the config tool provided with the EntLib. All of the categories have trace listeners assigned (DB, flat file, e-mail). Now, the problem. The only events that get logged (flat file, DB and e-mail) are of the Debug category.. As soon as I change a category to anything else, the event doesn't go through to the destination storage. I started playing with Filters and added Category Filter (allowed all of my category sources) and LogEnabled Filter (with Enabled = true).. Special Sources subtree contains 'All Events', 'Logging Errors and Warnings', 'Unprocessed Category', but they do not contain any trace listeners..

Have no idea what to do now.. Please help.

Thanks,

Alex
Apr 4, 2007 at 12:08 AM
Hrmm.. Well, I figured it out.. For each of the categories I had different source levels defined, but in the code I wasn't setting different .Severity values for logging event..

Would be VERY nice to have some document that actually explains relation between config values and the code requirements.. Much easier that way rather than 'try everything you can' approach..
Apr 4, 2007 at 7:24 PM
Hi Alex,

I see that you got hang of DataBase Trace listeners. I am having problems using this listener. I have stored procedures and tables. I am not getting any errors but the log information is not going to db either.

Here is my web.config.
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="Audit" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="WebSites1" 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}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}"
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="All" name="Audit">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
<add switchValue="All" name="General" />
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings" />
</specialSources>
</loggingConfiguration>

Here is my class file code
LogEntry le = new LogEntry();
le.Categories.Add("Audit");
le.Message = "Testing our DB Logging";
le.EventId = 1234;
le.Title = "Database Message";
le.Priority = 1;
Logger.Write(le);

If you can help me i will really appreciate that.
Thanks in advance.
Kamal
Apr 4, 2007 at 8:47 PM
Have you referenced Microsoft.Practices.EnterpriseLibrary.Logging AND Microsoft.Practices.EnterpriseLibrary.Logging.Database? Try to add a flat file listener and see if that helps?

Btw, all i see in your .config file is an Event Log listener.. Doesn't look like you have a DB listener there anyway, so no wonder why there is nothing in the DB. :)