This is the online documentation for PostSharp 4.3.
Download PDF or CHM. Go to v4.3 or v5.0
Walkthrough: Changing the Logging Back-End

This section describes how to change the logging back-end for a project or solution.

This topic contains the following sections:

The following table shows identifiers of the back-ends and the NuGet packages in which they are implemented. You will need this table in both scenarios.

Changing the logging back-end when using NuGet

When using the NuGet distribution of PostSharp, the Diagnostics Pattern Library comes as the PostSharp.Patterns.Diagnostics NuGet package, which contains common functionality and implements some of the back-ends. Other back-ends may require additional NuGet packages. The details are provided in the table above.

To change the logging back-end when using NuGet:

  1. Remove the NuGet package containing the previous back-end implementation, if any.

    Note Note

    The PostSharp.Patterns.Diagnostics NuGet package should always remain installed as long as you use any of the logging back-ends. This package contains the common logging functionality.

  2. Remove the libraries NuGet package of the previous back-end if any and if you'll not use the libraries in your project outside of PostSharp.

  3. Add the NuGet package containing the new back-end implementation, if the implementation is not contained in the PostSharp.Patterns.Diagnostics NuGet package already.

    Note Note

    If any other NuGet package is required by the back-end, it will be installed automatically by the NuGet Package Manager.

  4. Set the LoggingBackend property in the PostSharp project file (MyProject.psproj) to the name of the new logging back-end. Below is an example of PostSharp project file with the LoggingBackend set to "Trace".

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.postsharp.org/1.0/configuration" OverridesDefaultProject="false">
      <Property Name="LoggingBackend" Value="Trace" />
    </Project>
Changing the logging back-end when not using NuGet

When using a non-NuGet distribution of PostSharp, all the PostSharp plug-ins are contained in the distribution.

To change the logging back-end when not using NuGet:

  1. If you'll not use the back-end in your project outside of PostSharp, you can remove the assembly references and configuration from your project.

  2. Add the relevant assembly references and configuration of the new backend to your project. See the documentation of the back-end. Links are provided in the table above.

  3. Set the LoggingBackend property in the PostSharp project file (MyProject.psproj) to the name of the new logging back-end. Below is an example of PostSharp project file with the LoggingBackend set to "Trace".

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.postsharp.org/1.0/configuration" OverridesDefaultProject="false">
      <Property Name="LoggingBackend" Value="Trace" />
    </Project>