英文:
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.
<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 <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("You are welcome! :) ");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论