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
17
votes
2 answers

Multiple filters for one logger with Serilog

I am trying to setup Serilog with my ASP.NET Core application. I'd like to have one log file for all controllers, one for all services, one for the rest and ideally one which contains everything. Every controller is inheriting BaseController and…
Carsten Franke
  • 1,649
  • 2
  • 13
  • 30
17
votes
3 answers

Serilog with Autofac

I have a logger wrapper and I wanna inject serilog to it with following configurtion perse: var logger = new LoggerConfiguration() .WriteTo.RollingFile( AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "/Log-{Date}.txt") …
DarthVader
  • 52,984
  • 76
  • 209
  • 300
16
votes
9 answers

How to add 'request body' in serilog's output .net core?

I have a web API based on .net core 3.1. I'm using the SeriLog library as a logger. Here is my SeriLog Configuration. Serilog has been configured from 'appsettings.json'. I need to add 'request body' parameters to log's output if it exists. Is…
OguzKaanAkyalcin
  • 621
  • 2
  • 8
  • 25
16
votes
2 answers

Serilog is not writing log to Seq until Log.CloseAndFlush() is invoked

Serilog and Seq works fine when I log from WinForm/web application. I am facing problem only when I am using console application. Without writing Log.CloseAndFlush() it is not working. Following is my LoggerConfiguration Log.Logger = new…
Hasibul
  • 569
  • 2
  • 6
  • 21
16
votes
1 answer

Is it safe to use a static `Serilog.ILogger`

I am using Serilog. I want to write log entries with a SourceContext of the containing class. Is it safe (including thread safe) to do this: using Serilog; ... class Foo { private static readonly ILogger Log = …
James World
  • 29,019
  • 9
  • 86
  • 120
16
votes
2 answers

One logger for a multi-project solution

I am integrating Serilog into an existing multi-class layer and Multi-Assembly Solution that I've created. The previous logging technique I used was simply passing a string up the layers with events. I'd like to get away from this. I have read that…
TheColonel26
  • 2,618
  • 7
  • 25
  • 50
15
votes
1 answer

Getting error when upgrading from Serilog.Sinks.ApplicationInsights v3.1 to v4.0

I have an Azure Function that uses Serilog to write to AppInsights with Serilog AppInsights sink v3.1. The code in Startup.cs looks like this Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(config) …
Alex Monkey
  • 1,427
  • 1
  • 14
  • 16
15
votes
2 answers

Inject Serilog's ILogger interface in ASP .NET Core Web API Controller

All the examples I can find about using Serilog in an ASP .NET Core Web Application use Microsoft's ILogger interface instead of using Serilog's ILogger interface. How do I make it so that Serilog's ILogger can be injected via constructor,…
Lindsey1986
  • 381
  • 1
  • 3
  • 15
15
votes
2 answers

How do I interpret Serilog configuration in ASP.NET Core 2.1?

For some reason, I find it very hard to understand what's going on with Serilog configuration. I have a web api with .NET Core 2.1 and installed serilog.sink.logstash. My startup has: public void Configure(IApplicationBuilder app,…
Harris
  • 1,128
  • 4
  • 17
  • 41
15
votes
2 answers

Enable file logging on IIS for serilog

I want to enable file logging on IIS to resolve an issue locally on IIS. Following is the code I am using. It works when I run on visual studio and logs to a file but not when I deployed to IIS. Folder has enough permission to create a file and also…
CuriousGuy
  • 3,818
  • 4
  • 24
  • 28
15
votes
3 answers

Configure Serilog File sink to use one log file per application run

I want to configure Serilog to create one log file per app run. File name should be based on current date/time: 1st run: log_20180413_1020.txt 2nd run: log_20180413_1033.txt I didn't find how to do it in any File sink (Rolling, Alternative..) Any…
IgorStack
  • 799
  • 2
  • 6
  • 22
15
votes
1 answer

Serilog With API App in Azure

I've integrated Serilog into WebApi project developed with Asp.Net Core 2.0 This is the configuration code in Program.cs: Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); I…
ZENIT
  • 500
  • 2
  • 4
  • 16
15
votes
4 answers

ASP.NET Core 1.0 logging

I have ASP.NET Core web api project. Now I want to log the errors and events. I previously used ELMAH in my project but it seems that elmah is not available for ASP.NET Core. I referred to this Official link for configuring the default logging…
15
votes
1 answer

What is Serilog destructuring?

What is the purpose of Serilog's @ syntax? If I run the following: var dummy = new { Foo = "Bar", Date = DateTime.Now }; Log.Information("Dummy object: {Dummy}", dummy); Then I get an output to the console like so: Time: 16:20 [Level: Information]…
BanksySan
  • 27,362
  • 33
  • 117
  • 216
15
votes
1 answer

Serilog - Possible to Change DateTime/Timestamp Format in RollingFile Sink

The Current Output of RollingFile Sink for Date time is as follows 2015-04-06 18:40:54.400 +10:00 [Information] Hello World! Is there anyway to remove the TimeZone Offset? +10:00. To Achieve the following output; 2015-04-06 18:40:54.400…
Aaron Glover
  • 1,199
  • 2
  • 13
  • 30