The Loupe Agent is designed to work with the built-in Trace and Debug logging facilities. Because these are built into every version of the .NET framework, the Agent will automatically work with Trace by default.
To work with Trace, you need to:
Once you have Loupe working with Trace, you can maximize the value you get out of Loupe by reviewing Logging - Optimizing Trace Logging.
The built-in Trace and Debug logging capabilities of .NET are a great way to get started with logging. They provide good basic capabilities and are always available because they're built into every version of the .NET runtime. If no trace listeners are registered, the overhead of having Trace calls in your application is trivial.
Example Trace Logging on Application Startup |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; namespace ExampleApplication { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Trace.TraceInformation("Application starting"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); Trace.TraceInformation("Application exiting normally"); //When you're all done with Trace, it's a good idea to call close to have //all trace listeners flush and shut down gracefully. This helps the //Loupe Agent know that your application didn't crash. Trace.Close(); } } } |
The .NET Diagnostics classes include the Debug class which can take actions only when an application is compiled in Debug mode. This is particularly useful when you want to include extra messages that would "spam" the log in normal use or include sensitive information (like passwords) that should not be logged.
Debug Usage Example |
Copy Code
|
---|---|
private void ExecuteNonQuery(DbCommand command) { Debug.Assert(command != null); Debug.WriteLine("Starting to Execute Db Command"); if (command.Connection.State != ConnectionState.Open) { Debug.WriteLine("Command Connection isn't open - opening."); command.Connection.Open(); } Debug.WriteLine(string.Format("Executing Db Command On connection '{0}':", command.Connection.ConnectionString)); Debug.WriteLine(command.CommandText); command.ExecuteNonQuery(); Debug.WriteLine("Db Command Execution Complete"); } |
Nothing done by the Debug class will happen if the project is compiled in Release mode. In the above example (which is somewhat excessive even for debug use) none of the statements that start Debug would produce any execution code in a Release build, ensuring that there is no overhead to any work they do.