2

I'm bit confused on serilog support for .net framework 4.8

I want to implement serilog for logging in .net framework 4.8 asp.net webapi, but I didn't find any useful articles, including serilog official documentation.

I want to implement serilog database logging in .net framework 4.8

Earlier I have implemented serilog in .net 6 version and it's working Now I want to implement serilog database logging in webapi which is targeting.net framework 4.8

Guide me on that.

  • https://www.nuget.org/packages/Serilog/3.0.0-dev-01862#supportedframeworks-body-tab / It supports .NET 4.8 and .NET 4.8.1, among many others – canton7 Feb 23 '23 at 17:18
  • It would be great if you provide any suggestions or any links related to implementation of Serilog mssql database logging in .net framework 4.8. I see we can follow https://github.com/serilog/serilog-settings-appsettings article for using appconfig or web.config. But I'm bit confused how to provide db log table name and it's custom column names in app.config or web.config. Kindly guide me on that. – Sravani Yadav Feb 23 '23 at 17:36
  • Does this answer your question? [Install serilog and configure in an asp .net 4.7.1 webapi](https://stackoverflow.com/questions/54818504/install-serilog-and-configure-in-an-asp-net-4-7-1-webapi) – iamdlm Feb 23 '23 at 17:37

1 Answers1

2

Yes, it is working on .net framework 4.8 and it really took me a hard time. Here are what I did and I am able to see the log message with these implementations.

you will need to install Serilog.Sinks.Seq library from NuGet manager, and you will have the following code added to your packages.config.

<package id="Serilog" version="2.12.0" targetFramework="net48" />
<package id="Serilog.Formatting.Compact" version="1.1.0" targetFramework="net48" />
<package id="Serilog.Sinks.Console" version="4.1.0" targetFramework="net48" />
<package id="Serilog.Sinks.PeriodicBatching" version="3.1.0" targetFramework="net48" />
<package id="Serilog.Sinks.PeriodicBatching" version="3.1.0" targetFramework="net48" />
<package id="Serilog.Sinks.Seq" version="5.2.2" targetFramework="net48" />

in the web.config

<?xml version="1.0" encoding="utf-8"?>
...
<appSettings>
...
<add key="SeqFolder" value="the url or file path that you want to store the logger" />
...

in the Global.asax.cs

var log = new LoggerConfiguration().WriteTo.Seq(System.Configuration.ConfigurationManager.AppSettings["SeqFolder")                
            .MinimumLevel.Information().CreateLogger();
        Log.Logger = log;
        log.Information("This will show as soon as your application is running!");
         

this is about HOW you use it in application, in anywhere in your code, eg controller, you just need to use the following code to start logging anything you want to.

Log.Logger.Information("You are welcome! :) ");
user14181068
  • 269
  • 3
  • 7