Image may be NSFW.
Clik here to view.Behind Advent door number 19 is a simple treat – how to use Gibraltar with the logging capabilities of .NET.
As soon as the Gibraltar Agent is started within a process it begins listening to a number of sources of information, including:
- Trace Messages: Anything sent to System.Diagnostics.Trace will be routed into the Agent.
- Console Messages: If you write text to System.Console it will be copied into the Agent as well as sent on to any Console.
- Debug Messages: In a debug build anything written to System.Diagnostics.Debug will be output to any Trace listener and therefore routed to the Agent.
Since many third-party and Microsoft components send useful information to Trace Gibraltar automatically registers itself as a Trace Listener as soon as the agent is loaded (as well as registering to get a copy of all console messages) so there’s no configuration needed on your part. The only thing you need to worry about is that the Gibraltar Agent is actually started and eventually told to shut down. If you’re running in an ASP.NET application there’s nothing to do for this- the Gibraltar Agent for ASP.NET takes care of it all. Otherwise, you should explicitly start the agent early on in your application’s lifecycle and then shut it down when you’re sure your application is exiting. For details see:
- WinForms Application Setup Instructions
- WPF Application Setup Instructions
- Windows Service Setup Instructions
After that, you can freely send information strait to Trace, Debug, or Console and be sure that it’ll be captured by the Gibraltar Agent. If you have a third-party library that supports Trace you can enable that logging and it’ll get captured as well.
*Whew* That was easy! Have an idea on a more complicated problem for us to solve? Share your ideas with us on Facebook and you’ll have a chance to win a fantastic prize!