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

Serilog's ILogger injected using Log.ForContext, where T is the consumer

Serilog allows creating a context-aware logger: Log.ForContext() I would like to register Serilog with SimpleInjector in such a way that T is the type of the consumer, i.e. it is which class it is injected in to. e.g. public class Car { …
jameskind
  • 1,097
  • 2
  • 13
  • 28
13
votes
2 answers

Specify directory for Serilog rolling file path

Consider this app.config appSetting entry: This is done at app startup: Log.Logger = new LoggerConfiguration() .ReadFrom.AppSettings() …
Glenn Doten
  • 2,603
  • 3
  • 21
  • 22
13
votes
2 answers

How can I add a named property that is not part of the message template?

In some cases, I would like to add contextual information to a message (for instance currently authenticated user), without having to include it in the message template. I would like to accomplish this : logger.Information("Doing stuff {Foo} with…
tsimbalar
  • 5,790
  • 6
  • 37
  • 61
12
votes
0 answers

How to set telemetryConfiguration for Application Insights for Serilog via AppSettings

For my ASP.NET 5 Web Project I want to log to Application Insights via Serilog. Now I finally got everything working, but I cannot belive this is they way to go. I hope you can help me to improve it. The main problem I see, is that the…
Vincent Bitter
  • 1,000
  • 1
  • 6
  • 15
12
votes
1 answer

How to use Expression Template with appSettings in Serilog

I've a file sink configured in the appsettings.json of my application. It works perfectly but now I want to add an expression template to format the output in my file. As I can see, there's no way to set expression template using configuration…
mberube.Net
  • 2,120
  • 2
  • 29
  • 39
12
votes
3 answers

Correctly Injecting Serilog into .net core classes as Microsoft.Extentions.Logging.ILogger - Not ASP .Net Core

So I have a .Net Core Console application and a bunch of .Net core Libraries. Most of the classes in the libraries have constructors like this. public class ReportingManager { private ILogger _logger; Public ReportingManager(ILogger logger) …
Gaz83
  • 2,293
  • 4
  • 32
  • 57
12
votes
3 answers

How do I get a serilog enricher to work with dependency injection while keeping it on startup?

There is an answer here: How do I pass a dependency to a Serilog Enricher? which explains you can pass an instance in. However to do that I would need to move my logger setup after my dependency injection code has ran (in the startup.cs) This means…
NibblyPig
  • 51,118
  • 72
  • 200
  • 356
12
votes
2 answers

How to config `Serilog` to write to the application directory with the cofig file?

I'm using Serilog on a .net core. I want to config the log path to the application directory. I see there's an extension https://github.com/serilog/serilog-settings-configuration that enable Serilog to read from Configuration. In the example , the…
mosakashaka
  • 535
  • 1
  • 6
  • 19
12
votes
4 answers

Remove new lines from Message and Exception

I am using Serilog in an Asp dot net core application. I want my my log files to be human readable, but also be able to be parsed easily. The problem that I have come across is that exceptions are logged with line breaks. Some Microsoft events have…
Andrew Radford
  • 3,227
  • 1
  • 20
  • 25
12
votes
3 answers

Serilog not creating log file when running on Linux

I'm having problems to enable logging when running ASP.NET Core application on Linux. I'm using Serilog.Sinks.File (but also tried with RollingFile) with following configuration defined in appsettings: "Serilog": { "Using": [ "Serilog.Sinks.File"…
rjovic
  • 1,207
  • 2
  • 16
  • 37
12
votes
3 answers

How to remove properties from log entries in ASP.Net Core

I'm using Serilog with ASP.Net Core 2.0, writing to RollingFile using JsonFormatter. Followed the instructions here to configure: https://github.com/serilog/serilog-aspnetcore. Everything works great, but in every log entry I get the following…
Andrew
  • 1,139
  • 1
  • 12
  • 27
12
votes
1 answer

How do I pass a dependency to a Serilog Enricher?

I'm using Serilog in my application for logging. When I'm configuring the logger, I have code like this: var log = new LoggerConfiguration() .Enrich.With() .ReadAppSettings() .CreateLogger(); I want to inject some…
user2023861
  • 8,030
  • 9
  • 57
  • 86
12
votes
7 answers

Serilog - RollingFile Sink does not roll files based on date and size

I am using Serilog - RollingFile Sink, but it stores all data in a single file for a day. In my application, 1 GB log is written in a day. So I want to roll log file on the basis of date and size. How can I configure RollingFile Sink to roll files…
user1780538
  • 900
  • 3
  • 13
  • 22
12
votes
2 answers

How can I create an optional property in a Serilog output template?

I'm trying to create an global output template for serilog messages that follows the following format: {Timestamp:yyyy-MM-dd HH:mm:ss,fff} [{ComponentName}, {ApplicationName}, {ThreadId}] {Level} ({ErrorId}): {Message} {Exception} The trouble I'm…
Ken Sykora
  • 1,124
  • 13
  • 27
12
votes
1 answer

Serilog, Elmah or both for a ASP.NET MVC project?

I implemented Serilog for a ASP.NET MVC project which will be hosted in Azure and Serilog provides sinks to log to Azure storage. I then wanted a better way to handle exceptions and ran into this very informative article on integrating ASP.NET MVC…
DotnetDude
  • 11,617
  • 35
  • 100
  • 158