开发者

(Logging ApplicationBlock) Split log into 2 files according to severity

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?

开发者_Go百科

Thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜