Add Loupe to Your Project

Start by adding the Gibraltar Loupe Agent NuGet package

Enable Exception Logging

Add a couple lines to your App class and Loupe will log all unhandled exceptions.

using System.Windows;
using Gibraltar.Agent;

public partial class YourService : ServiceBase
{
    public YourService()
    {
        InitializeComponent();
    }
    protected override void OnStart(string[] args)
    {
        Log.StartSession();
    }
    protected override void OnStop()
    {
        Log.EndSession();
    }
}

Add Loupe Server for Exception Reporting

Add a couple more lines and Loupe Server will centralize log collection, analysis and error management.

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="gibraltar">
            <section name="server"
                     type="Gibraltar.Agent.ServerElement, Gibraltar.Agent" />
        </sectionGroup>
    </configSections>
    <gibraltar>
        <server autoSendSessions="true"
                useGibraltarService="true"
                customerName="YOUR LOUPE SERVICE ACCOUNT" />
        <!-- If you have an on-premises Loupe Server, use this instead:
        <server autoSendSessions="true"
                useGibraltarService="false"
                server="YOUR LOUPE SERVER" /> -->
    </gibraltar>
</configuration>

Or you can configure the server connection in code

protected override void OnStart(string[] args)
{
    Log.Initializing += Log_Initializing;
    Log.StartSession();
    // ...
}

private void Log_Initializing(object sender, LogInitializingEventArgs e)
{
    var server = e.Configuration.Server;
    server.AutoSendSessions = true;

    server.UseGibraltarService = true; // Using subscription Loupe Service
    server.CustomerName = &quot;YOUR LOUPE SERVICE ACCOUNT&quot;;

    // server.UseGibraltarService = false; // Using on-premises Loupe Server
    // server.Server = &quot;YOUR LOUPE SERVER&quot;;
}

Deploy Loupe Desktop or the Loupe Live Viewer along with your service so you can monitor your logs in real-time

That was easy! What's Next?

With just these few steps you're now collecting crucial details on every error, recording performance metrics and logging every trace message your service emits.

Learn more about Loupe in our Windows Service Developers Guide.