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

Unit test serilog configuration

I have a piece of code for setting up serilog based on some custom configuration combined with hosting environment. E.g. the application writes to one sink in development and another sink in production. I'm trying to figure out how to write tests…
Vegar
  • 12,828
  • 16
  • 85
  • 151
8
votes
2 answers

Override serilog minimumlevel for specific sink using appsettings.json

There is documentation for "globally" overriding MinimumLevel in code, xml and json. But can I override for a specific sink, using appsettings.json? For example, I want to log at warning level for class MyClass, but only for the console sink.
lonix
  • 14,255
  • 23
  • 85
  • 176
8
votes
2 answers

serilog multiple instance per functionality

While I have a general purpose logger for errors, exceptions etc that use rolling file sink to log stuff to my-{date}.log. However, I need another instance for audit to audit-{date}.log and another instance to write perf info to perf-{date}.log. How…
DarthVader
  • 52,984
  • 76
  • 209
  • 300
8
votes
2 answers

Serilog JSON config LoggingLevelSwitch access

Configuring Serilog using a JSON config, it is possible to configure log level switches as such: "LevelSwitches": { "$appLogLevel": "Debug", "$netLogLevel": "Information", "$sysLogLevel": "Error" }, "MinimumLevel": { "ControlledBy":…
Xorcist
  • 3,129
  • 3
  • 21
  • 47
8
votes
3 answers

Can I log to separate files using Serilog?

My ASP.NET Core 2.1 app logs to a Serilog file sink, all the "usual stuff" - i.e. app related stuff such as debug, monitoring, performance, etc. However we also need to log other data to a separate file. Not app related, but customer related - the…
lonix
  • 14,255
  • 23
  • 85
  • 176
8
votes
2 answers

SeriLog with AppInsights not writing to AppInsights

I am writing logs using Serilog with appinsights on an .NET CORE 2.0 project. i have configured SeriLog as follows, var loggerConfiguration = new LoggerConfiguration() .ReadFrom.Configuration(configuration) …
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
8
votes
3 answers

Map ILogger to Serilog's Logger after ASP.NET Core 2 logging update

From @nblumhardt's post: You can then go ahead and delete any other logger configuration that’s hanging around: there’s no need for a "Logging" section in appsettings.json, no AddLogging() anywhere, and no configuration through ILoggerFactory in…
leon
  • 762
  • 1
  • 10
  • 24
8
votes
3 answers

Serilog : how do you specify a filter expression in config file

I am trying to specify this filter in the appsettings .json file .Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore.Hosting.Internal.WebHost")) The above syntax works when specified in c# But trying to specify the same in a json file…
kolhapuri
  • 1,581
  • 4
  • 20
  • 31
8
votes
1 answer

Serilog - path to log file

i am trying to start working with serilog. The normal RollingFile doesn't fit my needs (i need the counting like logs\20160701-00002.txt), so i want to use the RollingFileAlternate as a sink. When using RollingFile i added loggerInstance = new…
Monika_Aydt
  • 111
  • 1
  • 1
  • 5
8
votes
3 answers

Method not found: 'Serilog.LoggerConfiguration

I have a main logger for my solution which is defined as Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.LiterateConsole(LogEventLevel.Verbose) …
TheColonel26
  • 2,618
  • 7
  • 25
  • 50
8
votes
1 answer

Where are the console logs in an asp.net core application hosted by IIS

I've added logging to an asp.net core application, using the excellent Serilog library. I have added sinks for both Sql Server and Literate console. The sql server sink works perfectly of course, but, well this is a little embarrassing, I have no…
ashilon
  • 1,791
  • 3
  • 24
  • 41
8
votes
2 answers

Log hangfire events using existing serilog

Im new to hangfire, and im trying to setup a way to log the events using my existing serilog logger in an asp.net web api. Here is my logger class: public static class LoggerInitializer { private static ILogger CreateLog() { var…
Jonas Olesen
  • 568
  • 5
  • 25
8
votes
1 answer

How to use Serilog with Unity?

Recencely I discoverd serilog ( structured logging for .net ) and saw a lot of its advantages. But I face some problems with it. I have 4 projects, one is web, one is infrastructure and the other two are windows services, I want to declare serilog…
jsDevia
  • 1,282
  • 4
  • 14
  • 37
8
votes
2 answers

Serilog machine name enricher for rolling file sink

I'm trying to use a couple of enrichers (machine name and thread ID for now) in conjunction with a rolling file sink and a Loggly sink. Whilst the Loggly events correctly contain the machine name and thread ID properties, I can't see these in the…
CyberDude
  • 8,541
  • 5
  • 29
  • 47
7
votes
2 answers

What is the difference between AddSerilog and UseSerilog in .NET 6 Web API?

I'm trying to configure Serilog for a Web API project in .NET 6. Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(builder.Configuration) .Enrich.FromLogContext() .WriteTo.Console() …
user246392
  • 2,661
  • 11
  • 54
  • 96