Post­Sharp Documentation / Logging / Configuring specific logging frameworks / Logging to Common.​Logging

Logging to Common.Logging

This article shows how to use PostSharp Logging and Common.Logging together.

To use PostSharp Logging with Common.Logging:

  1. Add PostSharp logging to your codebase as described in Adding Detailed Logging to your Solution.

  2. Add the PostSharp.Patterns.Diagnostics.CommonLogging package to your startup project.

  3. In the application startup file, include the following namespace imports:

    C#
    using Common.Logging;
    using Common.Logging.Simple;
    using PostSharp.Patterns.Diagnostics;
    using PostSharp.Patterns.Diagnostics.Backends.CommonLogging;

    In the application startup method, include the following code:

    C#
    // Configure Common.Logging to direct outputs to the system console.
    LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();
    
    // Configure PostSharp Logging to direct outputs to Common.Logging.
    LoggingServices.DefaultBackend = new CommonLoggingLoggingBackend();

    This example code instructs Common.Logging to write all log records to the system console. See the Common.Logging documentation for details.

If you run your application, you should also see the log in the console.

See Also