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
11
votes
1 answer

Serilog: Request Id implementation

Lately I have configured Serilog to play nice with ASP.NET Core 2 MVC app and next task is to trace incoming request to web app on every layer of the system. So basically, we want to propagate some token (like RequestId generated by Serilog to lower…
Macko
  • 906
  • 3
  • 11
  • 27
11
votes
2 answers

How can I get the current HttpContext in a SeriLog Sink?

I'm creating my own SeriLog sink implementing ILogEventSink using the Building a Simple Sink example with the intent of logging some information from the users claims. To get access to HttpContext in Core, I'd normally inject in an instance of…
Gavin Sutherland
  • 1,666
  • 3
  • 23
  • 36
11
votes
3 answers

'Serilog' already has a dependency defined for 'Microsoft.CSharp'

I am trying to install serilog and I'm getting error PM> Install-Package Serilog Install-Package : 'Serilog' already has a dependency defined for 'Microsoft.CSharp'. At line:1 char:1 + Install-Package Serilog + ~~~~~~~~~~~~~~~~~~~~~~~ …
LP13
  • 30,567
  • 53
  • 217
  • 400
11
votes
2 answers

Removing Default Properties in Serilog Output

In the Serilog output in a file, I see that the default is { "Timestamp": "2016-05-28T21:21:59.0932348+08:00", "Level": "Information", "MessageTemplate": "Processed {@Number} records in {@Time} ms", "Properties": { "Number":…
Bran
  • 617
  • 8
  • 21
11
votes
2 answers

Is it possible to get Timestamp in output template as DateTimeKind.Utc?

Currently when I use {Timestamp} in an outputTemplate it appears to have been generated by DateTime.Now and therefore being of DateTimeKind.Local flavor since, when I give it an "o" specifier it produces output similar to…
Sergei Z
  • 535
  • 3
  • 10
10
votes
1 answer

Can Serilog output level "Trace" instead of "Verbose"?

I'm using serilog with ASP.Net in .Net 5 and I'm using the Microsoft.Extensions.Logging.ILogger. The problem is when I put the following in my code: logger.Log(LogLevel.Trace, "Trace message") Serilog outputs a log level of "Verbose". I know that…
Mog0
  • 1,689
  • 1
  • 16
  • 40
10
votes
1 answer

Serilog slow, bad performance

Am I doing something wrong or Serilog has awful performance? Create a new Asp.Net Core 5.0 webapi project, add a reference to Serilog.AspNetCore nuget package and the following configuration code. Serilogs adds 15ms per request! In my maching jumps…
rm5432
  • 327
  • 1
  • 3
  • 10
10
votes
2 answers

How to log TestServer output to the test console

I'm currently writing an integration test (https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-5.0) for my ASP .Net Core 5 REST API. The API is using Serilog for logging (with the static Serilog Logger). I am running…
10
votes
1 answer

Is it possible to change colors in serilog?

I have just integrated Serilog in my dot net core project. It is working really well but I use a dark theme and some logs are really dificult to read. As an example: This is how I init Serilog: string environment = …
Notbad
  • 5,936
  • 12
  • 54
  • 100
10
votes
2 answers

How to get Serilog to use custom enricher from json config file

I wish to use formatted UTC timestamps in my Serilog output. I have written a custom enricher that works fine when called from C# code. public class UtcTimestampEnricher : ILogEventEnricher { public void Enrich(LogEvent logEvent,…
Paulus
  • 1,385
  • 16
  • 20
10
votes
2 answers

C# Serilog: how to log with String interpolation and keep argument names in message templates?

How to replace this code: string name = "John"; logger.Information("length of name '{name}' is {nameLength}", name, name.Length); with C# String interpolation like this or similar string name = "John"; // :-( lost benefit of structured logging:…
Artemious
  • 1,980
  • 1
  • 20
  • 31
10
votes
2 answers

ASP.Net Core Serilog How to read from log file during runtime

I'm working on a ASP.NET Core 3.1 application. I want to log events to file and be able to read them during application runtime. To do that I'm trying to use Serilog.Extensions.Logging.File NuGet package and then specifying log file path as…
Nazar Antonyk
  • 470
  • 4
  • 14
10
votes
1 answer

Unable to use Serilog with .Net Core 3 IHostBuilder

I'm trying to use Serilog in a .Net Core project. I have 2 services, the 1st one was upgraded from .Net Core 2.2 and in Program.cs it uses IWebHostBuilder to start the application. Here I created my logger and passed it as a parameter to…
Jeff Finn
  • 1,975
  • 6
  • 23
  • 52
10
votes
2 answers

How to setup configuration in .NET Framework for Serilog

Our team just moved one of our ASP.NET solutions from logging in log4net to Serilog (using iLogger) for logging. Our solution is .NET Framework 4.6. I can see Serilog configuration documentation online for setting up configuration in code as well as…
Ross Gustafson
  • 1,182
  • 3
  • 16
  • 32
10
votes
1 answer

Serilog writes the logs twice

I'm using Serilog with Elasticsearch sink with the configurations like this: Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .MinimumLevel.Override("Microsoft", LogEventLevel.Verbose) …
Mohsen Kamrani
  • 7,177
  • 5
  • 42
  • 66