Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup configuration in .NET Framework for Serilog

Our team just moved one of our ASP.NET solutions from logging in log4net to Serilog (using iLogger) for logging. Our solution is .NET Framework 4.6. I can see Serilog configuration documentation online for setting up configuration in code as well as some documentation in appsettings.json. We have Web.config configuration files. Our old log4net configuration resided completely in the csproj files.

Is there a place for configuration for Serilog and its sinks in .NET Framework (specifically in Web.config or its own XML configuration file)? Do we have to put the configuration into the code (when we create the logger object)? Can we specify the configuration for specific controllers and models we have, and, if so, where is there documentation? I know we could specify locations, log levels, etc. for log4net for specific groups or controllers and models in log4net, but unsure how to do that for Serilog. If you got links for any of this, please point me in the right direction. Thanks.

like image 440
Ross Gustafson Avatar asked Aug 16 '19 14:08

Ross Gustafson


People also ask

Does Serilog work with .NET framework?

It is compatible with both the . Net Framework and the . Net Core and supports many layout formats, such as JSON, text, console, and XML. Serilog is easy to set up and use, and it provides a lot of features and flexibility.

Does Serilog work with .NET 6?

Serilog is a robust API for logging with many configurations and sinks (outputs) and it is straightforward to get started in any . NET version. With . NET 6 the way we used to configure Serilog as a logging provider in .

Does Serilog support .NET core?

Serilog is a third-party, open-source library that integrates nicely with ASP.NET Core and allows developers to easily log-structured event data to the console, to files, and various kinds of log targets.


1 Answers

After more investigating (and I can't believe I missed this earlier), the documentation here states you can edit the web.config file. In case anyone is looking for the configuration for web.config, there you go.

like image 77
Ross Gustafson Avatar answered Nov 03 '22 00:11

Ross Gustafson