Logging with Common.Logging
This article shows how to use PostSharp Logging and Common.Logging together.
To use PostSharp Logging with Common.Logging:
Add PostSharp logging to your codebase as described in Getting Started with PostSharp Logging.
Add the PostSharp.Patterns.Diagnostics.CommonLogging package to your startup project.
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.