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
34
votes
8 answers

Serilog in Windows-Service not writing to logfile

I am using Serilog within an TopShelf Service, logging to the console and a rolling file. When running the service in a console my messages are written to the logfile, but when I install the service and run it no logging occurs. Is there anything…
Gope
  • 1,672
  • 1
  • 13
  • 19
33
votes
3 answers

Can a Serilog.ILogger be converted to a Microsoft.Extensions.Logging.ILogger?

I have code that logs to Microsoft.Extensions.Logging.ILogger (and extension methods, mostly). I have configured Serilog to actually do the logging. I can't find a way to convert a Serilog.ILogger to Microsoft.Extensions.Logging.ILogger. I assumed…
Chris
  • 959
  • 2
  • 9
  • 20
32
votes
2 answers

How to add my own properties to Serilog output template

I have a small application that is receiving messages from a service bus, which can send through several different types of events for different users. Based on the type of event, a different function is called. I'm logging information in each of…
Steven
  • 18,761
  • 70
  • 194
  • 296
31
votes
5 answers

Configuring Serilog RollingFile with appsettings.json

I'm trying to configure Serilog for a .NET Core project. Here's what I have in my appsettings.json: "Serilog": { "MinimumLevel": "Verbose", "Enrich": ["FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId"], "WriteTo": [ …
Alexander
  • 1,317
  • 1
  • 12
  • 12
31
votes
6 answers

Serilog - multiple log files

I am using Serilog for logging and cant' figure out how to separate log events to different files. For example, I want to log errors to error_log-ddmmyyyy.txt and warnings to warn_log-ddmmyyyy.txt. Here goes my logger configuration: Log.Logger = new…
Anton Kiprianov
  • 358
  • 1
  • 3
  • 5
29
votes
4 answers

How to configure and use Serilog in ASP.NET Core 6?

Since the recently introduced new structure of the Program.cs startup code, the documentation confuses me a bit. In the officially provided Serilog.AspNetCore example and in the Serilog.Sentry example, they use .UseSerilog() on the WebHostBuilder. I…
ˈvɔlə
  • 9,204
  • 10
  • 63
  • 89
29
votes
1 answer

How to use Serilog in .NET Core Console app

I wanted my application to have capability of logging to a file, so I started to look for something more than default .NET Core 2.2 logging framework. I see that Serilog might do the job. However, I cannot find any document on how to setup Serilog…
mnj
  • 2,539
  • 3
  • 29
  • 58
28
votes
1 answer

Pattern to use Serilog (pass ILogger vs using static Serilog.Log)

Background In a new project where Serilog was chosen as the logger I automatically started passing around ILogger interface. The code accesses Log.Logger once and from then the classes that desire logging accept ILogger via constructor injection. I…
tymtam
  • 31,798
  • 8
  • 86
  • 126
28
votes
3 answers

How do I automatically tail (delete) older logs using Serilog in a .Net WPF application?

I'm using Serliog in a .Net WPF application. Is there a way that I can "tail" (delete) the log files automatically when they are over N days old?
JohnB
  • 3,921
  • 8
  • 49
  • 99
26
votes
2 answers

.NET Core - Serilog - IHostBuilder does not contain a definiton of UseSerilog()

trying to follow this tutorial : https://nblumhardt.com/2019/10/serilog-in-aspnetcore-3/ I managed to add the Serilog to my app (.NET Core 3.1) but I cannot modify the CreateHostBuilder function, since it does not recognize UseSerilog() function I…
phil123456
  • 1,192
  • 2
  • 10
  • 26
26
votes
3 answers

How to get Microsoft.Extensions.Logging in console application using Serilog and AutoFac?

We have common BL classes in a ASP.NET Core application that get in the ctor: Microsoft.Extensions.Logging.ILogger In ASP.NET Core, the internal infrastructure of ASP.NET handles getting the ILogger via the LoggerFactory. We now want to reuse…
gdoron
  • 147,333
  • 58
  • 291
  • 367
25
votes
3 answers

Why isn't Serilog writing Debug messages even when the level is set to Debug?

I wrote the following line to create my logger in a C#/WPF application, but the Debug messages do not show up in the logs. What am I missing? I am using serilog.sinks.file version 4.0.0. The release build produces information level events, but…
shawn1874
  • 1,288
  • 1
  • 10
  • 26
25
votes
2 answers

How to log complex object using Serilog in valid json format?

I have this structure: public class LogRequestParameters { public string RequestID { get; set; } public string Type { get; set; } public string Level { get; set; } public string DateTime { get; set; } public string…
user1780538
  • 900
  • 3
  • 13
  • 22
24
votes
4 answers

Is it possible to display Serilog log in the program's GUI?

With the logging system Serilog is it possible to display the log in a text box, or a list view or some other GUI control; what is the mechanism to get it there?
TheColonel26
  • 2,618
  • 7
  • 25
  • 50
23
votes
2 answers

How to use Serilog ForContext

I am new to Serilog and I am having a hard time figuring out how to use the context functionality. When I run the code below the output file does not include the the report id. Any ideas what I am missing? var logger = new LoggerConfiguration() …
Marco
  • 2,453
  • 3
  • 25
  • 35