Logging With the Stackify API
  • 2 Minutes to read
  • Dark
    Light
  • PDF

Logging With the Stackify API

  • Dark
    Light
  • PDF

Article summary

You can log messages directly via the Stackify API without the use of a logging framework.  You can get more information at the Stackify Github page.

Use a Logging Framework!
Please note that we recommend using NLog, Serilog, or log4net. Those frameworks allow you to send your logs to multiple different outputs. If you decide to not use Stackify products in the future, your code also isn't hard coded against Stackify's libraries by using a logging framework.

Our logging appenders for NLog, log4net, and Serilog simply "wrap" around StackifyLib. If you plan to use StackifyLib directly for logging, we suggest at least abstracting and centralizing how you call it incase you decide not to use it later.

Download the Stackify API

To get the Stackify API package, enter the following command into the Package Manager Console:

Install-Package StackifyLib

When prompted, enter your Activation Key found in the Settings > Account Info page of the Retrace Portal.

Syntax for Using the API

You will notice in the code sample below that the Stackify library offers both standard logging via the Queue() method, as well as Exception Logging via the QueueException() method. When logging anything other than an exception, use Queue(). When logging an exception, you will want to use QueueException() so that the error will show up in the Error Dashboard and will also include full stack trace details and other information that is only captured when using QueueException().

try
{
    StackifyLib.Logger.Queue("DEBUG", "Entering MyMethod()");
}
catch (Exception ex)
{
    StackifyLib.Logger.QueueException(ex);
}

Adding Additional Debug Information

If there are custom properties that you want to add to your logged details, you can easily add them as shown above.

catch (Exception ex)
{
    StackifyLib.Logger.QueueException(ex, new { customerid = 1 });
}

Error Results on Unmonitored Servers:

If you are logging errors from a server that doesn't have a Retrace monitoring agent on it, you have to add an Environment key to the appSettings section of your configuration, as it cannot be inferred by Retrace without an agent running on the machine. It should also be noted that if you are logging errors for your application and that application doesn't appear as an app in the App Stacks page, the only way to see error telemetry is from the global Error Dashboard page, as there will be no App Dashboard for that application if it's not installed on a server that is being monitored. Below is the required configuration entry if logging from an unmonitored server:

    <appSettings>
        <add key="Stackify.ApiKey" value="Your Activation Key" />
        <add key="Stackify.AppName" value="Your App Name"/> <!-- optional - will be inferred by Stackify if this is running on a monitored server -->
        <add key="Stackify.Environment" value="Your Environment"/> <!-- optional - will be inferred by Stackify if this is running on a monitored server -->
    </appSettings>

Was this article helpful?