PostSharpLoggingConnecting to Source and Target Logging FrameworksLogging with Common.​Logging
Open sandboxFocusImprove this doc

Logging with 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 Getting Started with PostSharp Logging.

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

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

    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:

    // 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


Other Resources

Example project: PostSharp.Samples.Logging.CommonLogging