Step by step: Serilog with ASP.NET Core

Last week I wrote about .NET Core and Microsoft Bot Framework and I’m still learning and playing with it. The thing is that once I implemented more features and deployed the bot to Azure it didn’t work. So I had to find a way to log and trace what was happening in order to diagnose and fix the problem.

This time I decided to give a chance to Serilog and as you should know by now, getting the correct dependencies to work with .Net Core is not always easy, so here is my Step by step: Serilog with ASP.NET Core

1. Add the following dependencies in your project.json file
2. Add the following lines to the constructor of your Startup class
3. Add the following line to the configure method of your Startup class
4. Inject the logger to your services or controllers

Hope it helps!

13 thoughts on “Step by step: Serilog with ASP.NET Core

      1. Are you sure this works for Core 1.1? I downloaded and reviewed your sample and do not see how it could work. I started a Core 1.1 project fresh in VS 2017 and cannot get Serilog added to the pipeline? Help?

        1. Yeap, the sample works as is for .Net Core 1.1. You should be able to clone it and execute dotnet restore and dotnet run without issues. I’m using Visual Studio Code and .Net Core SDK 1.0.1

      2. I answered my own problem! So the issue was I was reading in two places the same packages to install. However, it requires two Seq.Extensions.Logging and Serilog.Extensions.Logging. After fixing this I was able to pipeline the logs to Seq.

  1. Anyone get this working with Azure Functions? Not having any luck. 🙁 I keep getting the missing method exception.

    Method not found: ‘Microsoft.Extensions.Logging.ILoggerFactory Serilog.SerilogLoggerFactoryExtensions.AddSerilog(Microsoft.Extensions.Logging.ILoggerFactory, Serilog.ILogger, Boolean

Leave a Reply