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.
You can configure the Agent in the App.Config of your service or through code. For more information see Developer's Guide - Agent Configuration.
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"); } } } } |