Failover in Logging 2.0

Topics: Logging Application Block
Apr 5, 2007 at 6:26 PM
In Logging 1.1 when you setup the DB sink and if it failed it would write the logs to EventLog i cannot get that to work.

I set up 2 Trace Listners
- Database Trace Listener
- Formatted EventLog TraceListener

But for My Category I only added "Database Trace Listener" because i want it to log only to my db my when the connection to the db fails i expect it to log to the eventlog and seems like that does not happen. DO i have to setup some special configuration. Any help would be gratly appeciated.

-T
Apr 5, 2007 at 7:24 PM
Hi Terry -

To do this in EntLib 2.0+ you need to add a reference to the Event Log TraceListener to the "Logging Errors and Warnings" special source.

HTH
Tom
Apr 5, 2007 at 8:08 PM
I did add a reference to "Formatted EventLog TraceListener" to the Special SOurce --> Logging Errors & Warnings but still if i type in a wrong db name i expect it to log to the event log as it cannot find the database but does not log it to the EVENT LOG.

Enclosed is my WEB.config:

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="Library" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add databaseInstanceName="DEV" writeLogStoredProcName="WriteLog2"
addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
name="Database Trace Listener" />
<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;)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
name="Text Formatter" />
</formatters>
<logFilters>
<add minimumPriority="0" maximumPriority="130" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
name="Priority Filter" />
<add enabled="true" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
name="LogEnabled Filter" />
</logFilters>
<categorySources>
<add switchValue="All" name="Library">
<listeners>
<add name="Database Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Database Trace Listener" />
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<dataConfiguration defaultDatabase="DEV" />
<connectionStrings>
<add name="DEV" connectionString="Database=LoggingDB1;Server=LoggingServer;user id=DBusername;password=DBpassword;"
providerName="System.Data.SqlClient" />
</connectionStrings>


Thanks in advance
Apr 6, 2007 at 12:33 AM
I see that you have the Database Trace Listener referenced in your "Errors" special source too:
<errors switchValue="All" name="Logging Errors & Warnings">
  <listeners>
    <add name="Database Trace Listener" />
    <add name="Formatted EventLog TraceListener" />
  </listeners>
</errors>
This isn't a good idea, as if the database is unavailable then writing the error will also fail. I can't remember what happens when one of the "errors" Trace Listeners fails, but it's a good idea to make sure you only use very reliable mechanisms so you don't lose errors. Try taking this reference out of the errors special source and let me know if that helps.

Tom
Apr 6, 2007 at 5:46 PM
Thanks Tom for the quick response. I did change the "errors" to "Formatted EventLog TraceListener" and that seems to work. Also if i have 2 trace listners of the first one fails "Database Trace Listener" them it wont go to the second one "Formatted EventLog TraceListener" in my case above but if the 1st one is successful then the second also works..... Seems like it is a look and breks of a look if the when it fails.... IS this by design?

1) Do i need to have Trace Listned for each of these special sources as mentioned below?

<specialSources>
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="Database Trace Listener" />
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</notProcessed>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>

thanks in advance,
T
Apr 6, 2007 at 6:46 PM
Hi Terry -

I'm not sure if that was a deliberate design decision, however as I mentioned before we recommend only using "reliable" Trace Listeners in the errors source to minimize the possibility of failures.

It is not necessary to put any trace sources in all (or any) of the "special sources" - you should only add them if you want to log events when certain things happen.

Tom