Serilog Exceptionless Sink in .NET Core 1.1

624 Views Asked by At

How can the Serilog Exceptionless Sink be used with .NET Core 1.1?

The Serilog.Sinks.Exceptionless README isn't clear and doesn't work for .NET Core 1.1 where I have put the configuration in the appsettings.json file.

{
  "Serilog": {
    "Using": ["Serilog.Sinks.Literate"],
    "MinimumLevel": ["Debug"],
    "WriteTo": [{
      "Name": "LiterateConsole"
    }],
    "Enrich": ["FromLogContext"],
    "Properties": {
      "Application": "MyAppServer"
    }
  }
}

Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(config)
            .CreateLogger();
    }
}

I obviously need to set up the API key somewhere, too.

Can anyone provide a clear description of how this can be configured, please?

2

There are 2 best solutions below

0
On BEST ANSWER

In JSON you can add additional sinks to the "WriteTo" list and add arguments like apiKey in the "Args" block:

{
  "Serilog": {
    "Using": ["Serilog.Sinks.Literate"],
    "MinimumLevel": ["Debug"],
    "WriteTo": [{
      "Name": "LiterateConsole"
    }, {
      "Name": "Exceptionless",
      "Args": { apiKey: "12345" }
    }],
    "Enrich": ["FromLogContext"],
    "Properties": {
      "Application": "MyAppServer"
    }
  }
}
0
On

I think it's

Log.Logger = new LoggerConfiguration()
    .WriteTo.Exceptionless(
        apiKey: "yourApiKey", 
        additionalOperation: b => b.AddTags("ASP.NET Core Example Logger"))
    .CreateLogger();