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

How to override ASP.NET Core configuration array settings using environment variables

TL;DR In an ASP.NET Core app, I have an appsettings.json config file which uses a JSON array to configure a collection of settings. How do I override a setting of one of the array objects using environment variables? Background I'm using Serilog in…
James Skimming
  • 4,991
  • 4
  • 26
  • 32
78
votes
8 answers

Suppress SQL Queries logging in Entity Framework core

I have a console .net core app that uses entity framework core. The app uses logging framework to write to file and console: serviceProvider = new ServiceCollection() .AddLogging() .AddDbContext(options => …
vmg
  • 9,920
  • 13
  • 61
  • 90
61
votes
3 answers

Filter Serilog logs to different sinks depending on context source?

I have a .NET Core 2.0 application in which I successfully use Serilog for logging. Now, I would like to log some database performance statistics to a separate sink (they are not for debugging, which basically is the purpose of all other logging in…
David Nordvall
  • 12,404
  • 6
  • 32
  • 52
58
votes
4 answers

Use Serilog with Microsoft.Extensions.Logging.ILogger

I've created a .NET Core 3.1 project using a Host, the IoC container with IServiceCollection and implemented logging allover the place using the ILogger interface from Microsoft.Extensions.Logging. I now need to implement more advanced logging…
morteng
  • 1,133
  • 2
  • 9
  • 22
48
votes
9 answers

Serilog RollingFile

I am trying to use WriteTo.RollingFile with Serilog as the following to write one file per day: var log = new LoggerConfiguration().WriteTo.RollingFile( @"F:\logs\log-{Date}.txt", …
TechNerd
  • 910
  • 1
  • 10
  • 19
44
votes
5 answers

Serilog's AddSerilog is not recognized

I'm trying to call loggerFactory.AddSerilog(); as per this documentation, but the AddSerilog method is not recognized: "Error CS1061 'ILoggerFactory' does not contain a definition for 'AddSerilog' and no extension method 'AddSerilog' accepting a…
ashilon
  • 1,791
  • 3
  • 24
  • 41
42
votes
3 answers

Add custom properties to Serilog

I'm using Serilog with an MS SQL Server sink in my application. Let's assume I have defined the following class…
Marius Schulz
  • 15,976
  • 12
  • 63
  • 97
41
votes
3 answers

Different Minimum Level Logs Serilog

Is there a way to differentiate what level is logged between the different loggers for Serilog? I want to be able to log MinimumLevel Debug to the console output but only Warning and above to my file output. I am using ASP.NET Core 2.1 and this is…
jollyroger23
  • 665
  • 1
  • 6
  • 19
39
votes
5 answers

Add Username into Serilog

I have this Serilog configuration in program.cs public class Program { public static IConfiguration Configuration { get; } = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) …
Muflix
  • 6,192
  • 17
  • 77
  • 153
38
votes
3 answers

Exception destructuring in Serilog

Serilog has a convenient way of destructuring objects as shown in this example: logger.Debug(exception, "This is an {Exception} text", exception); logger.Debug(exception, "This is an {@Exception} structure", exception); The first line causes the…
Vagif Abilov
  • 9,835
  • 8
  • 55
  • 100
38
votes
5 answers

Which Serilog sink to use for sending to Logstash?

We started using Serilog in combination with Elasticsearch, and it's a very efficient way to store structure log data (and later visualize them using tools like Kibana). However, I see the advantage of not writing log data directly to the backend…
Vagif Abilov
  • 9,835
  • 8
  • 55
  • 100
36
votes
3 answers

C# ASP.NET Core Serilog add class name and method to log

I recently added logging to my ASP.Net Core project. Currently the log writes to a .txt file in this format: {Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception} For example: 2017-11-30 13:58:22.229 +01:00 [Information]…
Jeroen
  • 1,625
  • 3
  • 16
  • 28
36
votes
7 answers

Solving error - Unable to resolve service for type 'Serilog.ILogger'

I am trying to implement SeriLog in ASP.NET core application (.NET framework) Below are steps I performed so far- 1) Added below references in Project.json "Serilog": "2.2.0", "Serilog.Extensions.Logging": "1.2.0", "Serilog.Sinks.RollingFile":…
Sanket
  • 19,295
  • 10
  • 71
  • 82
36
votes
5 answers

Serilog - Output/Enrich All Messages with MethodName from which log entry was Called

Is there anyway to enrich all Serilog output with the Method Name. For Instance consider If I have the following; Public Class MyClassName Private Function MyFunctionName() As Boolean Logger.Information("Hello World") Return True …
Aaron Glover
  • 1,199
  • 2
  • 13
  • 30
34
votes
4 answers

Serilog : Log to different files

I am logging events of all types to single Json file irrespective of LogLevel. Now I have a requirement to log some custom performance counters to a seperate Json file. How can this be done in Serilog. Should I create different Logger Instance and…
Shetty
  • 1,792
  • 4
  • 22
  • 38
1
2 3
99 100