0 votes
by (630 points)

We are using PostSharp.Diagnostics with nlog for logging. How do I integrate PostSharp+nlog with LogWriterBase ?

1 Answer

0 votes
by (72.7k points)

When using LogWriterBase just simply implement the WriteMessage() method. Example:

class PostSharpNLogWriter : LogWriterBase
{
    // PostSharp+nlog _logger;

    public PostSharpNLogWriter()
    {
        // initialize PostSharp+nlog here
        // _logger = PostSharp+nlog.Create();
    }

    protected override void WriteMessage(string message)
    {
        // use PostSharp+nlog to write already formatted log message
        //_logger.Log(message);
    }
}

If you want to customize the logger, override the Write method and add desired logic there. When you are done with your code, call either base.Write which will format the message and issues WriteMessage or call the WriteMessage directly yourself.

...