Serilog是否支持.NET Framework 4.8?

huangapple go评论61阅读模式
英文:

Does serilog have support for .NET Framework 4.8

问题

我有点困惑Serilog在.NET Framework 4.8上的支持

我想在.NET Framework 4.8 ASP.NET WebAPI中实现Serilog日志记录,但我没有找到任何有用的文章,包括Serilog官方文档。

我想在.NET Framework 4.8中实现Serilog数据库日志记录

之前我已经在.NET 6版本中实现了Serilog,它正常工作。现在我想在定位.NET Framework 4.8的WebAPI中实现Serilog数据库日志记录。

请指导我。

英文:

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.

答案1

得分: 3

是的,它在.NET Framework 4.8上运行,并且确实花了我很多时间。
以下是我所做的事情,我能够看到这些实现中的日志消息。

您需要从NuGet管理器中安装Serilog.Sinks.Seq库,并且会将以下代码添加到您的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.Seq" version="5.2.2" targetFramework="net48" />

在web.config中:

<?xml version="1.0" encoding="utf-8"?>
...
<appSettings>
...
<add key="SeqFolder" value="您希望存储记录器的URL或文件路径" />
...

在Global.asax.cs中:

var log = new LoggerConfiguration().WriteTo.Seq(System.Configuration.ConfigurationManager.AppSettings["SeqFolder"])                
                .MinimumLevel.Information().CreateLogger();
Log.Logger = log;
log.Information("这将在应用程序运行时立即显示!");

这是关于您在应用程序中如何使用它的,无论在代码的任何地方,例如控制器中,您只需使用以下代码来开始记录您想要的任何内容。

Log.Logger.Information("欢迎您!:)");
英文:

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.

&lt;package id=&quot;Serilog&quot; version=&quot;2.12.0&quot; targetFramework=&quot;net48&quot; /&gt;
&lt;package id=&quot;Serilog.Formatting.Compact&quot; version=&quot;1.1.0&quot; targetFramework=&quot;net48&quot; /&gt;
&lt;package id=&quot;Serilog.Sinks.Console&quot; version=&quot;4.1.0&quot; targetFramework=&quot;net48&quot; /&gt;
&lt;package id=&quot;Serilog.Sinks.PeriodicBatching&quot; version=&quot;3.1.0&quot; targetFramework=&quot;net48&quot; /&gt;
&lt;package id=&quot;Serilog.Sinks.PeriodicBatching&quot; version=&quot;3.1.0&quot; targetFramework=&quot;net48&quot; /&gt;
&lt;package id=&quot;Serilog.Sinks.Seq&quot; version=&quot;5.2.2&quot; targetFramework=&quot;net48&quot; /&gt;

in the web.config

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
...
&lt;appSettings&gt;
...
&lt;add key=&quot;SeqFolder&quot; value=&quot;the url or file path that you want to store the logger&quot; /&gt;
...

in the Global.asax.cs

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

this is about <b>HOW</b> 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(&quot;You are welcome! :) &quot;);

huangapple
  • 本文由 发表于 2023年2月24日 01:09:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548108.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定