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
3 answers

How to prevent Serilog from logging every little step as information automatically?

I want to use Serilog for my .Net 5 Web Api project. I installed the packages Serilog.AspNetCore v4.1.0 Serilog.Sinks.Console v4.0.0 and changed the Program.cs file to public sealed class Program { public static void Main(string[] args) { …
Question3r
  • 2,166
  • 19
  • 100
  • 200
8
votes
1 answer

Hangfire: add JobId globally for logging to Serilog

I am trying to add the Hangfire JobId (and other properties) to all of my jobs without having to add it to each job method. In Startup.cs I added a promising filter solution however I don't know how to apply it to my test method and I am not even…
ratanmalko
  • 449
  • 4
  • 20
8
votes
1 answer

Serilog different levels for different sinks

I have the following piece of c# code for writing logs with multiple sinks (console and file), how do i restrict the console to log only (info, warn and error) and file to log everything. var outputTemplate = "[{Level:u3}]…
nen
  • 621
  • 2
  • 10
  • 26
8
votes
0 answers

Mixing Serilog configuration from code and app.config

I would like to set the logFileName from code but I would like to have all other parameters configurable from the app.config file. If I put some configuration in code and some in app.config, one overwrites the other. Is this possible? static private…
Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55
8
votes
1 answer

serilog async sink not flushing buffer to disk on shutdown

When using the serilog async sink with the file sink (and buffered = true), log entries are being lost on shutdown. I'm guessing it's the buffer not flushing to disk, even though it is being called. I'm not sure why this is happening, but I'm pretty…
Bill
  • 256
  • 3
  • 10
8
votes
3 answers

Unable to resolve service for type 'Serilog.ILogger' : "AspNetCore.Serilog.RequestLoggingMiddleware"

I am new to programming, I am trying to implement a logging solution for .net core project. I want to collect Default and Microsoft category logs. APPSETTING.JSON { "Serilog": { "MinimumLevel": { …
UtpMahesh
  • 410
  • 10
  • 25
8
votes
2 answers

How to use dependency injection in Serilog Sink?

I follow this article. Developing a sink But I need to injection IHttpClientFactory. public class MySink : ILogEventSink { //... public MySink(IFormatProvider formatProvider, IHttpClientFactory httpClientFactory) { //... …
Libron
  • 129
  • 2
  • 9
8
votes
3 answers

Serilog set flush interval

I'm using serilog in my ASP Core 2.2 application. Everything works great but I can't set flushToDiskInterval. It means that I want to flush logs to disk every minute for example but logs are flushed just as they're created. My Program.cs…
Artyom
  • 654
  • 2
  • 7
  • 16
8
votes
6 answers

Serilog multiple files appsettings.json

Im trying to configure serilog to write to multiple files, with no luck whatsoever. With this configuration it just writes to the second file? { "AllowedHosts": "*", "Serilog": { "Using": [ "Serilog.Sinks.File" ], "MinimumLevel":…
TuomasK
  • 1,849
  • 3
  • 13
  • 19
8
votes
3 answers

Serilog in Azure Functions

Each method in Azure Functions can have a Microsoft.Extensions.Logging.ILogger injected into it for logging. Using WebJobsStartup with a startup class you can change the logging to use Serilog using the following syntax: [assembly:…
TheHvidsten
  • 4,028
  • 3
  • 29
  • 62
8
votes
4 answers

Resolve generic Microsoft.Extensions.Logging.ILogger with Unity - get InvalidCastException

I am trying to register a generic ILogger (from Microsoft.Extensions.Logging, not from Serilog) in Unity (version 4). I've got the following class: public class MyClass { private readonly Microsoft.Extensions.Logging.ILogger _logger; …
Julian
  • 33,915
  • 22
  • 119
  • 174
8
votes
1 answer

Serilog logs collected by Fluentbit to Elasticsearch in kubernetes doesnt get Json-parsed correctly

Using the EFK Stack on Kubernetes (Minikube). Have an asp.net core app using Serilog to write to console as Json. Logs DO ship to Elasticsearch, but they arrive unparsed strings, into the "log" field, this is the problem. This is the console…
imbageek
  • 609
  • 5
  • 18
8
votes
1 answer

Serilog not writing to file with .NET Core 2.2

P.S. The code below works fine. The problem was between the monitor and the chair. Answer by @jpgrassi sent me in the right direction to resolve it. I have the following in program.cs: public class Program { public static void Main(string[]…
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
8
votes
2 answers

Serilog does not write log to file while using InProcess hosting model in ASP.NET Core 2.2

If I use newly introduced InProcess hosting model in ASP.NET Core 2.2 as follows: netcoreapp2.2 InProcess Serilog does not…
TanvirArjel
  • 30,049
  • 14
  • 78
  • 114
8
votes
3 answers

Unit Test - How to test a `void` method that just inserts a log message (Serilog)

I need to test a method of type void, it just inserts a message on my LOG variable using a LOG framework (Serilog). See the implementation example: public class MyClass { public MyClass(ILogger logger) { this.logger =…
Igor
  • 3,573
  • 4
  • 33
  • 55