Loupe - Log - Monitor - Resolve
Loupe / Getting Started / .NET Framework / Using Loupe with Console Applications / Using Loupe with Console Applications - Integrating The Agent
In This Topic
    Using Loupe with Console Applications - Integrating The 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 Console Application
    Copy Code
    using System;
    using Gibraltar.Agent;
    namespace SampleConsole
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    //Start the Loupe session as soon as we enter so we capture everything that happens
                    Log.StartSession();
                    //Your console application logic starts here.
                }
                catch (Exception ex)
                {
                    //If we have an unhandled exception we want to record it and indicate we've crashed.
                    //the false means the application can't continue, therefore has crashed.
                    Log.RecordException(ex, "Main", false);
                }
                finally
                {
                    //Now that we're about to exit we need to put Loupe into shutdown mode.
                    //The message is not used if we're in a Crashed status, so it reflects normal exit.
                    Log.EndSession("Application Exiting Normally");
                }
            }
        }
    }
    

     

    See Also