Loupe - Log - Monitor - Resolve
Loupe / Developer's Guide / For .NET Core / 6 / 8 / Logging / Developer's Guide - Logging - Directly to Loupe
In This Topic
    Developer's Guide - Logging - Directly to Loupe
    In This Topic

    Prerequisites

    To log information directly using the Loupe API you need to add a reference to the Loupe Agent for .NET Core/.NET 5 (Loupe.Agent.Core).  This is the only file required.  By adding the reference most setup and deployment tools will automatically distribute this file with your application.

    The Loupe Log API is a set of direct methods broken out by severity:

    Logging Direct to Loupe
    Copy Code
    public void LogSample()
    {
        Log.Critical("Period.Delimited.Category", "This is a critical problem",
            "We are writing a test message with multiple insertion strings: {0} {1} {2}",
            "string", 124, DateTime.Now);
        Log.Warning("Period.Delimited.Category", "This might be a problem problem",
            "You don't have to provide insertion strings if you don't want to");
        //Any of the different severities can include details of an exception.  Don't bother
        //dumping it in the message area; it'll all be showing in the Loupe Desktop under the Exception.
        Exception ex = new InvalidOperationException("This is an example invalid operation exception");
        Log.Error(ex, "Your Application.Exceptions", "We had an odd exception but managed to recover",
            "Here's a description of what we were doing.  We don't need to provide exception data.");
        //If you think the application might crash immediately after you call to record the message
        //you might want to make just this message synchronous.
        Log.Critical(LogWriteMode.WaitForCommit, "Your.Category", "We had a problem and may crash",
            "Just like our first method above we can now provide extended detail with insertion strings");
        Log.Verbose("Your.Category", "This is our lowest severity message",
            "Verbose is like a debug or success message - below all other severities.");
    }
    

    Using your own Central Log Class

    If you already have a central logging class you can gateway calls into Loupe by using the Write methods.

    Advanced Logging Direct to Loupe
    Copy Code
    private void LogDirectAdvancedSample()
    {
        //using the Write method you can perform additional tasks that aren't accessible through the
        //Trace-compatible API.
        Log.Write(LogMessageSeverity.Information,
            "This is the simplest form of write, and is identical to Log.TraceInformation");
        //One special case is for important messages that you need committed to disk before continuing
        //such as when logging during an unhandled exception.  There is a performance penalty, so this option
        //is not set by default.
        Log.Write(LogMessageSeverity.Critical, LogWriteMode.WaitForCommit,
            "This statement will not return until the log message is committed to disk");
        //and the variation with passing exceptions and additional parameters to insert are also supported.
        //see the documentation for Log.Write for other overloads.
    }
    

    For the most advanced functionality (used primarily when bridging data from a foreign log system into Loupe, such as Microsoft.Extensions.Logging) you can use the WriteMessage methods.  These require the most work but delegate the most capability to your code. 

    See Also