Ori
Ori

Reputation: 125

how to override error method in c# log4net

I would like to ask if it possible to override the log methods or create a new one with extra properties in the method.

at the moment you can use it:

GlobalContext.Properites["Details"] = "some Info";
Log.Error("Some info",Exception);

I would like to use it:

Log.MySpecialError(Details, Message, Exception);

any advice will be appreciated

Ori

Upvotes: 1

Views: 2529

Answers (1)

Khan
Khan

Reputation: 18162

Create your own extension method.

It must be defined in a static class, and be a static method. E.g.

Definitions:

public static class Log4NetExtensions
{
    public static void MySpecialError(this Log log, string details, string message, Exception exception)
    {
        //Do something with parameters
    }
}

Use:

Log.MySpecialError(details, message, ex);

Upvotes: 5

Related Questions