Logging

Overview

Fanray uses Serilog and Structured Logging to log to several different sources Console, Log files, Seq and Application Insights.

The logging level and output sources can be configured in appsettings.json. By default in Development it logs to Console, Seq and Application Insights and in Production Logs files and Application Insights.

Structured Logging

Structured Logging enables you to dump entire objects as JSON into the logs and later search for them with their properties.

_logger.LogDebug("Show {@BlogPost}", blogPost);

Log files

Log files are on server file systems, on Azure you can find them by open up Kudu then go to d:\home\site\wwwroot\logs

Kudu Logs

Seq

Seq is a great logging tool during development. You can download and install it from https://getseq.net/. Its configuration is in appsettings.json. To use Seq during development go to http://localhost:5341.

{
    "Name": "Seq",
    "Args": {
        "serverUrl": "http://localhost:5341"
    }
}

As an example, when I publish a new post from Open Live Writer, Seq records the following. It shows a round trip of request with id “0HLH1ICD1KGGF:00000001“, the bottom rectangle shows the start of the request while the top rectangle marks the finish of it.

Seq

Useful info when using Seq

Application Insights

Applicatioin Insights is used in both dev and prod. In the appsettings.json there is an entry for InstrumentationKey

  "ApplicationInsights": {
    "InstrumentationKey": ""
  },

A couple things to note

  • When leaving the key blank your local Application Insights will log your last debugging session.
  • Or you can give it a key of an Application Insights on Azure to store the logs.
  • When deploy to Azure, go to your App Service > Configuration, under Application Settings section, create an entry for APPINSIGHTS_INSTRUMENTATIONKEY and put the key there.

Caching
Testing