Chat Support
Loupe - Log - Monitor - Resolve
Loupe / Getting Started / .NET Framework / Using Loupe with Windows Services / Using Loupe with Windows Services - Integrating the Loupe Agent
In This Topic
    Using Loupe with Windows Services - Integrating the Loupe Agent
    In This Topic

    It's important that the Loupe Agent be initialized as soon as possible in the lifecycle of your application to ensure it can capture information.  This can be done by adding a single Trace statement if your application doesn't reference Loupe or by making any Loupe logging call, for example Log.StartSession.

    Configuring the Loupe Agent

    You can configure the Agent in the App.Config of your service or through code.  For more information see Developer's Guide - Agent Configuration

    Ensuring the Loupe Agent Initializes and Shuts Down

    In this scenario the Loupe Agent is called directly.  Configuration is still entirely loaded from the App.Config file; this example is extended to use programmatic configuration in Developer's Guide - Agent Configuration through Code.

    Code Changes to integrate the Agent with your Windows Service
    Copy Code
    using System.ServiceProcess;
    using Gibraltar.Agent;
    namespace ServiceSample
    {
        public partial class YourService : ServiceBase
        {
            public YourService()
            {
                InitializeComponent();
            }
            protected override void OnStart(string[] args)
            {
                //we want to be sure the session has started.  This is safe to call repeatedly.
                Log.StartSession();
            }
            protected override void OnStop()
            {
                //We want to switch to shutdown mode so we exit cleanly and get the very last message.
                Log.EndSession();
            }
        }
    }
    

    This process is different than the normal integration method because of how services are started and stopped through the Service Control Manager (SCM).  If you have multiple services in the same assembly you should add this code to each. 

     

    See Also