Enterprise Library Logging DefaultCategory

Topics: Building and extending application blocks, General discussion, Logging Application Block
Apr 18, 2007 at 6:09 AM
I am using .NET 1.1 with Enterprise Library 1.0. I am using a Database Sink to write to Log tables and I have a
Separate Custom Sink to write to flat file.

What I am trying to do is use the Database Sink but if Database sink has some error, then Log should be written to
File sink. To do this I set the DefaultCategory as General and that points to custom File sink.
So if an error happens at Database sink, then shouldn't Log be written to default category and sink ???

Do I have to write some code to implement writing to a file if an error occurs in Database Sink?

Database Sink writes error messages to Event Log in case of error which is ok.
I just want to serialize Log object and write it to file in event of error writing to Database sink.

Is it possible to have a backup sink in case of error of Database sink ???

Let me know if you need more information. Any help is appreciated.


Apr 18, 2007 at 11:50 PM
Edited Apr 18, 2007 at 11:51 PM
Ok, I found some information but I am not sure how to use it.

Logging library has Sinks\DefaultLogDestination.cs which as the comments below says should get backup destination but I am not sure what I need to do so that it can use the backup sink in case of error.

/// <summary>
/// Represents a backup destination that is used if the configured logging destination fails.
/// Log messages are written to the event log.
/// </summary>
Apr 18, 2007 at 11:59 PM
My memory on v1 is getting pretty hazy, but IIRC the block was hard-coded to use the event log as the failover sink. In v2+ you can use any TraceListener in the "Errors" special source for logging failover.

Apr 19, 2007 at 2:41 PM
Edited Apr 19, 2007 at 2:42 PM
Thanks for your response. Unfortunately we have to use v1 as it is used by other projects too but I am going to push for v2 as soon as possible.

Do you know if there is any relation between CategoryID and Categories you define in Enterprise Lib Configuration tool. I do not see CategoryID in the Config file loggingDistributorConfiguration.config but DefaultLogDestination.cs has function GetCategoryId to get CategoryID and in my case it always gets 0.

Comments in GetCategoryId function says it Reads the category ID from the extended properties dictionary but if CategoryID is related to Categories then maybe if I set it in case of error then it may log to sinks other then Event Log.