Sending Azure App Service .NET Core Logs to Graylog

Pre-requisites

You’ll need:

Procedure

First, add the following packages to your application:

Next, add the following to Program.cs, at the bottom of the CreateDefaultBuilder method:

.UseSerilog((hostingContext, loggerConfiguration) =>
             loggerConfiguration.ReadFrom
.Configuration(hostingContext.Configuration));

Next, configure the appsettings.jsonfile, cleaning the existing Logging config and adding the following:

"Serilog": {
    "Using": [ "Serilog.Sinks.Graylog" ],
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "Graylog",
        "Args": {
          "hostnameOrAddress": "GRAYLOG_INSTANCE_URL",
          "port": "12201",
          "transportType": "Udp"
        }
      }
    ],
    "Properties": {
      "Application": "APPLICATION_NAME"
    }
  },

Do this for the appsettings.Development.json file to allow console logging when in Development:

"Serilog": {
    "Using": [ "Serilog.Sinks.Console" ],
    "MinimumLevel": "Information",
    "WriteTo": [
      { "Name": "Console" }
    ],
    "Application": "APPLICATION_NAME"
  }

Verification

Testing the application locally, check to see that you have console logging activated.

Once working, deploy the application to your Azure App Service and verify logs are being sent to Graylog.

To change the Application name, set the “Serilog:Properties:Application” configuration value.