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

How can I reconfigure Serilog without restarting the application?

In a long running process (such as a Windows service or an ASP.NET application) it’s sometimes desirable to temporarily increase the log level without stopping the application. NLog can monitor logging configuration files and re-read them…
Robin van der Knaap
  • 4,060
  • 2
  • 33
  • 48
11
votes
3 answers

Is it possible to use Serilog with OpenTelemetry?

Is it possible to use Serilog with OpenTelemetry? https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/logs/getting-started/README.md
Xavier John
  • 8,474
  • 3
  • 37
  • 51
11
votes
1 answer

Serilog : choose which sink to log at runtime

I'm going to implement Serilog within .net standard 2.0 library. I'm looking for a way to choose which sink(s) should be used for each log line. Lets say that we define 2 sinks within the configuration (console & file) : Log.Logger = new…
Kurt Colemonts
  • 133
  • 1
  • 7
11
votes
1 answer

Serilog - how to customize date in rolling file name?

In Serilog, you can easily enable rolling log files: Log.Logger = new LoggerConfiguration() .WriteTo.File("log-.txt", rollingInterval: RollingInterval.Day) .CreateLogger(); This will create a new log file every day in the following…
Phil K
  • 4,939
  • 6
  • 31
  • 56
11
votes
2 answers

BeginScope with Serilog

I want to use the feature the Microsoft.Logger has at Serilog directly, the BeginScope feature. I know that I can use Microsoft ILogger and setup Serilog to be the underlying logger but it's too much trouble at this point of the app. I want to know…
Menelaos Vergis
  • 3,715
  • 5
  • 30
  • 46
11
votes
1 answer

Overriding MinimumLevel doesn't work in Serilog

Trying to set minimum log level for Serilog 2.8.0 (in .NET 4.6.2). Logging is working fine, but not the Override feature. Here is my Program.cs: using System; using LogTest1.Classes; using Microsoft.Extensions.Configuration; using Serilog; using…
Kristian Sik
  • 123
  • 1
  • 1
  • 6
11
votes
1 answer

How to push custom properties to Serilog’s LogContext without adding other context properties?

In a .Net Core 2.2 API, I am trying to use Serilog for logging to SQL Server to take advantage of its structured logging capabilities. Besides the standard fields (Id, Timestamp, Level, Message, MessageTemplate, LogEvent), I need to capture the…
11
votes
2 answers

In Serilog, how can I remove empty brackets from JSON formatted log messages when using {Properties} format specifier?

I have the following outputTemplate string: var formatString = "{NewLine}[{Timestamp:dd-MMM-yyyy HH:mm:ss}] {Level} {SourceContext}{NewLine}{Properties:j}{NewLine}{Message:lj}{NewLine}{Exception}"; I have several enrichers configured to add and…
Rob L
  • 3,073
  • 6
  • 31
  • 61
11
votes
4 answers

Serilog not writing to File (.net core 2.2)

I am writing a web service that is using Serilog. I was having problems getting files to write out (but console logging worked). I noticed that the setup changed when .net core 2.0 came out based on this and this pages' explanation. However, now, I…
Killnine
  • 5,728
  • 8
  • 39
  • 66
11
votes
1 answer

Does Serilog.Sinks.Console sink get any benefits from wrapping to Serilog.Sinks.Async sink?

I using Serilog inside my aspnet core app for logging. And i need to write log events to console pretty frequently (300-500 events per second). I run my app inside docker container and procces console logs using orchestrator tools. So my question:…
Frank59
  • 3,141
  • 4
  • 31
  • 53
11
votes
1 answer

How can a TextWriter be used as a source for Serilog?

StackExchange.Redis writes log messages to a TextWriter. It does not use the ILogger interface for logging. I would like to turn messages written to a TextWriter, into Serilog debug level messages. Thoughts?
Richard Collette
  • 5,462
  • 4
  • 53
  • 79
11
votes
2 answers

Adding Serilog ILogger to a static class

I'd like to add a Serilog Log to a static class in my program like this (DataHelper is the class name): private readonly ILogger _log = Log.ForContext(); But this leads to the error message: static types cannot be used as type…
disasterkid
  • 6,948
  • 25
  • 94
  • 179
11
votes
2 answers

Options for controlling Destructuring of request object

I've run into a problem that I'm struggling to find a clean solution for, and Googling has not made me any wiser. The situation (1) We have our own assembly for setting up and adding a Serilog logger to any of our projects (consistent logging…
Mashton
  • 6,037
  • 2
  • 25
  • 35
11
votes
2 answers

Using Serilog with .Net core and App Insights

I have used App insights directly for application logging before and I have seen that .Net core platform also creates trace events that goes to App insights. In a new .Net core API application, I'd like to use Serilog for application logging and…
frosty
  • 2,421
  • 6
  • 26
  • 47
11
votes
5 answers

How to Log to Elastic Search by NLog or SeriLog with authentications

We are currently use azure scale set (many VMs on one source group with load balance and one availability set), we used to use NLog to log our web app action and errors, but now we asked/needs to use Elastic Search and also use centralized log for…
Bashar Abu Shamaa
  • 1,998
  • 2
  • 21
  • 36