Questions tagged [serilog]

Serilog is a .NET library which provides diagnostic logging to files, the console, and so-on. Consider using this tag along with the .net framework version you are using for extra clarity

Serilog is a library that provides diagnostic logging to files, the console, and so-on. It is easy to set up, has a clean API, and is portable between recent .NET platforms.

Unlike other logging libraries for .NET, Serilog is built with structured log data in mind. Parameters passed along with log messages are not destructively rendered into a text format. Instead, they're preserved as structured data that can be written in document form to a data store.

Useful links

2233 questions
7
votes
1 answer

.Net Core 3.1 - Set ForContext for Serilog with Microsoft Ilogger interface

How do I use the ForContext method for a Serilog logger using the ILogger interface from Microsoft.Extensions.Logging? Here's the code: private readonly ILogger _logger; //DI code here .... //inside some…
mk_yo
  • 752
  • 1
  • 12
  • 39
7
votes
5 answers

Serilog is not creating log SQL table when I run the application in .NET 5

I have the appsettings.json setup to create the log table automatically with "autoCreateSqlTable": true However, I checked SQL but the table is nowhere to be found. I can't seem to find what is causing it to not create and log the…
KB_Shayan
  • 632
  • 8
  • 24
7
votes
3 answers

Using serilog in a class library referenced by other projects

I have a solution containing multiple .NET Core API and windows services. How can I integrate Serilog in such a way that I will not be required to make changes at several different places for adding a column or changing some property? I'm thinking…
Mysterious288
  • 365
  • 5
  • 24
7
votes
2 answers

Is there a way to set Serilog formatter variables via appsettings.json?

I have the following appsettings.json configuration: { "Serilog": { "Using": [], "MinimumLevel": { "Default": "Information", "Override": { "Microsoft": "Warning", "System":…
Rob Packwood
  • 3,698
  • 4
  • 32
  • 48
7
votes
2 answers

Serilog, Microsoft.Extensions.Logging and Autofac

I have an Asp Net Core API that targets the .Net Framework 4.6.1. In this project I use Serilog with Microsoft.Extensions.Logging and also Auofac for DI. Using ILogger< T> logger with DI in the controller constructor works perfectlly and I also get…
RSxx
  • 355
  • 1
  • 4
  • 14
7
votes
3 answers

How to unit test Serilog's LogContext Properties

We have a fairly simple netstandard2.0 project for custom middleware that uses Serilog's static LogContext to copy specified HttpContext headers to the log context. I'm trying to write a unit test where I set up a logger that uses a DelegatingSink…
Kizmar
  • 2,465
  • 3
  • 20
  • 27
7
votes
2 answers

Serilog `rollOnFileSizeLimit` doesn't work with configuration file

When configure Serilog by configuration file(with nuget package Serilog.Settings.Configuration), it doesn't create rolling log file when size limit is reached. As suggested in this question and this issue, I'm using Serlog.Sinks.File (version…
mosakashaka
  • 535
  • 1
  • 6
  • 19
7
votes
2 answers

How to configure a Serilog sink for logging to CloudWatch

I would appreciate some guidance in setting up a Serilog sink for AWS CloudWatch with .NET Core. I'm using appsettings.json for configuration but I am unable to put the settings in the logger. When trying to write log information to CloudWatch this…
JPG
  • 545
  • 3
  • 19
7
votes
4 answers

Is there a way to turn off logging that Hangfire does with serilog?

Is there a way to turn off logging that Hangfire does with serilog? We are using our own abstraction and I don’t want all this extra noise coming from the Hangfire logger while using serilog. // INIT call under web project namespace…
Kaushik Thanki
  • 3,334
  • 3
  • 23
  • 50
7
votes
1 answer

Configuring Serilog.Extensions.Logging.File

Following the instructions at Nicholas Blumhardt's page and later the Serilog github page, I am having issues getting Serilog to work. Specfically Error CS1061 'ILoggerFactory' does not contain a definition for 'AddFile' and no extension…
Hecatonchires
  • 1,009
  • 4
  • 13
  • 42
7
votes
1 answer

Exclude specific endpoint serilog logging using aspnet core

We have an aspnetcore application and we have a healthcheck that makes request to an endpoint every x seconds. Our API is using serilog, logging level information which log each request made to the API. My question is: How can we filter to exclude…
Rafael Miceli
  • 2,014
  • 6
  • 22
  • 34
7
votes
1 answer

Serilog with a custom template and JSON formatter

I'm using Serilog with ASP.NET Core 2.1, and configure it via the appsettings.json. The default template doesn't include {SourceContext}, so I use my own template which includes it. But I also want structured logging with JSON. I read somewhere in…
lonix
  • 14,255
  • 23
  • 85
  • 176
7
votes
2 answers

SeriLog in Asp.Net Core web app does not inject dependency properly

In Startup.cs Configure() method, I setup the logger like below: Serilog.Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .Enrich.FromLogContext() .WriteTo.RollingFile(new…
frosty
  • 2,421
  • 6
  • 26
  • 47
7
votes
1 answer

ASP.NET - Serilog - Multiple sinks each one for a different use

I want to use Serilog for logging because I worked with it and it fits my needs. The difference in this case is that I need to log different modules and I would like each module to be logged in a different folder and even maybe in a different…
Asaf Epelbaum
  • 556
  • 1
  • 9
  • 22
7
votes
3 answers

Custom LogEventLevel with Serilog

I'm using Serilog and Seq with a .Net project. My main objective is to log some specific events. I would like to have my own log event level (like "Warning", "Verbose", "Information"...). But I don't really know if it's possible or not to have my…
Régis NIOX
  • 741
  • 2
  • 12
  • 30