Log4net custom log objects and application

I would like to extend log4net to accept custom log objects as a parameter. For instance:

        public class MyLogObject
    {
        public string PropA;
        public int PropB;
    }

    private MyLogObject entry = new MyLogObject() {PropA = "FooBar", PropB = 1};
    Log.Debug(entry);

... this should work like exceptions.

At the second stage, user log objects should be written to the database by the user database application. The user database application will be similar to ADONetAppender, but with a few modifications, such as an internal buffer queue for log entries.

Does anyone know if this works with log4net, and if there are any examples that can help me how to do this?

The properties of my log object and database fields are fixed, so there is no need to configure them.

, log4net "MyAppender" "MyRenderer". SQL-insert-statement, . , .

+3
2

ThreadContext ( , )

log4net.ThreadContext.Properties [ "MyLogObject" ] = ;

. "ToString()", :

date% -5level% property {MyLogObject} -% message% newline

log4net. , , .

+3

AdoNetAppender? BufferingAppenderSkeleton.

MyLogObject , ToString(). %%:

public class MyLogObject
{
    public string PropA;
    public int PropB;

    override public string ToString()
    {
        return PropA + " " + PropB;
    }
}
+1

Source: https://habr.com/ru/post/1734567/


All Articles