Post­Sharp Documentation / Logging / Configuring specific logging frameworks / Logging to Loupe

Logging to Loupe

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

To use PostSharp Logging with Loupe:

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

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

  3. Follow the instructions of the first step Loupe configuration tutorial to properly initialize Loupe for your application kind.

    In the following examples, we will show instructions for a console or WinForms application.

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

    C#
    using Gibraltar.Agent;
    using PostSharp.Patterns.Diagnostics;
    using PostSharp.Patterns.Diagnostics.Backends.Loupe;

    In the application startup method, include the following code before any logged code:

    C#
    // Initialize Loupe.
    Log.StartSession();
    
    // Configure PostSharp Logging to use Loupe.
    LoggingServices.DefaultBackend = new LoupeLoggingBackend();

    If you followed the Loupe configuration tutorial for a different type of application, do not forget to set the DefaultBackend just after the call to Log.StartSession().

  4. Before the application exits, include the following code:

    C#
    // Initialize Loupe.
    Log.EndSession();
  5. In order to enable source file information, create an XML file named postsharp.config in your project with the followig content:

    <?xml version="1.0" encoding="utf-8"?>
    
    <Project xmlns="http://schemas.postsharp.org/1.0/configuration">
    
      <Logging xmlns="clr-namespace:PostSharp.Patterns.Diagnostics;assembly:PostSharp.Patterns.Diagnostics">
        <Profiles>
          <LoggingProfile Name="Default" IncludeSourceLineInfo="True" />
          <LoggingProfile Name="Exceptions" IncludeSourceLineInfo="True" />
        </Profiles>
      </Logging>
    
    </Project>
  6. At this point, you should be able to use Loupe Viewer to see the live log of your running application. You can download Loupe Viewer and open it in the background. When you start your application, you will see a desktop notification from Loupe. Click on this notification to open the live log. Note that the live log will disappear as soon as Log.EndSession has been called.

  7. Configure your application to send data to Loupe server as described in the second step of the Loupe configuration tutorial.

    You will need to add some settings in your app.config or web.config. Replace the customerName attribute with the name of your Loupe subscription. If you don't have a Loupe subscription, you can sign up for a free trial.

    <configuration>
      <configSections>
        <sectionGroup name="gibraltar">
          <section name="publisher" type="Gibraltar.Agent.PublisherElement, Gibraltar.Agent" />
          <section name="server" type="Gibraltar.Agent.ServerElement, Gibraltar.Agent" />
        </sectionGroup>
      </configSections>
      <gibraltar>
        <publisher productName="Your Product" applicationName="Your Application" />
        <server autoSendSessions="True" sendAllApplications="True" useGibraltarService="True" customerName="Your Loupe Service Name"  />
      </gibraltar>
    </configuration>
See Also