views:

16

answers:

1

I want to be able to route all error messages to error.log.txt and all information messages to info.log.txt (regardless of categories). Is it possible?

Thanks

+1  A: 

It's very much possible. Since you haven't provided exact details I can provide a generic solution to this. Write an enum that defines the levels/categories of logging involved with your application (or better yet start a log class library if you're creating your own from scratch and place the enum in it).

public enum LogCategory
{
    Info,
    Error,
    Fatal,
    Debug
}

Now when you write a method for your logging to write to a log you could make the enum a required argument to the method.

public WriteToLog(string logMessage, LogCategory category)
{
    switch(category)
    {
        case LogCategory.Info:
            // write to Info.log.txt
            break;
        case LogCategory.Error:
        case LogCategory.Fatal:
            // write to Error.log.txt
            break;
        case LogCategory.Debug:
            // write to Debug.log.txt
            break;
        default:
            // validate more
            break;
    }
}

That will get you headed in the right direction.

jlafay
Thanks for the answer, but I was looking for a solution that involved only configuration tweaking (like the one supported by the log4net framework). Of course, developing a custom listener would allow me to customize it, but as I said, I was looking for a configuration switch (which doesn't exist apparently).One other issue I have with MSAB is the lack of hierarchical categories that can be turned on/off using prefixes (again, like in log4net).I'm probably thinking too much in terms of log4net's way of doing things and Logging AB was designed with a completely different mindset.
Florin Sabau