SFTP logging and Postsharp

0 votes
asked Feb 17 by Prabhakar (270 points)

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

1 Answer

0 votes
answered Feb 17 by Lukas Matyska (39,480 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.

...