Wednesday, December 15, 2010

How to add category prefix to log4net message?

Programmer Question

I like to add category prefix to all the messages on the existing logging messages. However it is tedious to add this prefix to all the existing logging messages one by one. Is there a way in I can just add an attribute to the class level then all the messages in this class will be logged for certain category?



Instead of the way right now as below,



Log.Info("[Ref] Level 1 Starts ...");


I really want to something like this or a different way to define the log4net.ILog.



[LoggingCategory("Ref")]
public class MyClass
{
public void MyMethod()
{
Log.Info("Level 1 Starts ...");
}
}


Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails