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

serilog format SourceContext for showing only assembly name

I configured my project to use Serilog for logging using dependecy injection. I use the following schema in the classes constructor: namespace FlickPopper.API.Controllers { public class ValuesController : Controller { private…
mnieto
  • 3,744
  • 4
  • 21
  • 37
22
votes
1 answer

ASP.NET Core 2.0 using Serilog to log stacktrace when exception is thrown

So I've recently started to build a asp.net core application and for the logging i'm using SeriLog. This was working fine until recently I found out that most of the time the stacktrace of an exception is not being transferred to my logs. I'm using…
Jeroen
  • 1,625
  • 3
  • 16
  • 28
19
votes
2 answers

Serilog DI in ASP.NET Core, which ILogger interface to inject?

Context I've successfully configured Serilog in my ASP.NET Core application, only the DI part remains. Question Now I have two ILogger interfaces, one is Serilog.ILogger the other is Microsoft.Extensions.Logging.ILogger. Both works based on my…
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
19
votes
2 answers

Output logs to Xunit using Serilog Static Logger

I use serilog in my projects with the static logger approach - it's nice and easy to be able to call Log.X on my class libraries rather than injecting a logger class everywhere. However when it comes to unit/integration testing, if a test has failed…
aspirant_sensei
  • 1,568
  • 1
  • 16
  • 36
19
votes
4 answers

Using Asp.Net Core 2 Injection for Serilog with Multiple Projects

I have Serilog configured for Asp.Net Core 2.0 and it works great via .Net Core dependency injection in my startup web project (if I use it through Microsoft.Extensions.Logging), but I can't access it from any other project. Here's what I…
platypusjh
  • 667
  • 1
  • 7
  • 16
19
votes
4 answers

Serilog + serilog-sinks-elasticsearch +ElasticSearch Auth

I am far from being a Dev with any .net experience, but the dev team at work would like to use Serilog along with serilog-sinks-elasticsearch to push logs into my ELK stack. Looking at the config for serilog-sinks-elasticsearch, there doesn't seem…
Phil
  • 765
  • 2
  • 8
  • 26
19
votes
3 answers

How to turn off Serilog?

We are using Serilog to log items into a db with a Windows service, and the users wanted to be able to do a manual run, so we made a button (on a web page) to make a call to the same code (as a module, not the service itself). When we added in the…
bowlturner
  • 1,968
  • 4
  • 23
  • 35
18
votes
2 answers

How to handle deprecation of IWebHostBuilder.UseSerilog() when IWebHostBuilder is still needed?

The UseSerilog() extension is deprecated* for IWebHostBuilder in serilog-aspnetcore version 5.0.0. However I'm still using a IWebHostBuilder and a Startup class (aspnetcore 6), and IWebHostBuilder is not deprecated. Since deprecation implies future…
daniel327
  • 331
  • 2
  • 10
18
votes
2 answers

OpenTracing doesn't send logs with Serilog

I'm trying to use OpenTracing.Contrib.NetCore with Serilog. I need to send to Jaeger my custom logs. Now, it works only when I use default logger factory Microsoft.Extensions.Logging.ILoggerFactory My Startup: public void…
Darkside
  • 470
  • 3
  • 20
18
votes
1 answer

How to output event source Class Name in serilog RollingFile outputTemplate?

The RollingFile.outputTemplate that I am using for my sink in configuration is as below: The output log I…
Ajay Jadhav
  • 2,417
  • 4
  • 21
  • 26
17
votes
1 answer

Invalid cast from 'System.String' to 'Serilog.Core.IDestructuringPolicy'

From studying Serilog.Sinks.AzureTableStorage I have the following In Main var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var logger = new LoggerConfiguration() …
Kirsten
  • 15,730
  • 41
  • 179
  • 318
17
votes
1 answer

How to force Serilog to log only my custom log messages

I configured Serilog in appsettings.json to log entries into Logstash via tcp in my asp net core web api app the following way: { "Serilog": { "Using": [ "Serilog.Sinks.Network" ], "MinimumLevel": { "Default": "Information" }, …
Dmitry Stepanov
  • 2,776
  • 8
  • 29
  • 45
17
votes
1 answer

How to write Serilog output to console in Visual Studio Unit Tests?

I am trying to write unit tests with output to log - Serilog. But when I am debugging them in Visual Studio (Test Explorer) I can't see the Serilog output in console. Any ideas? public abstract class AbstractTest { static AbstractTest() { …
mojmir.novak
  • 2,920
  • 3
  • 24
  • 32
17
votes
1 answer

How to get current Serilog MinimumLevel

Is there a way to get the minimum log level from Serilog's current configuration in a controller or middleware?
andre_ss6
  • 1,195
  • 1
  • 13
  • 34
17
votes
3 answers

Add user to the log context when using Serilog and Asp.Net Core

I'm trying to use Serilog together with my ASP.Net Core 1.0 project. I just can't seem to get the current logged in user added to properties logged. Has anyone figure this out yet? I have tried this: using System.Threading.Tasks; using…
Søren Rokkedal
  • 285
  • 1
  • 3
  • 8