简体   繁体   English

将 .NET 5 升级到 .NET 6 和 NLOG 后,NLog 将日志插入数据库的问题

[英]NLog issue inserting logs to DATABASE after upgrading .NET 5 to .NET 6 and NLOG

I have the following in my CSPROJ file我的CSPROJ 文件中有以下内容

    <PackageReference Include="NLog.Config" Version="4.7.15" />
    <PackageReference Include="NLog.Schema" Version="5.0.4" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
    <PackageReference Include="NLog" Version="5.0.4" />
    <PackageReference Include="NLog.Database" Version="5.0.4" />
    <PackageReference Include="NLog.Extensions.Logging" Version="5.0.4" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="5.1.4" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.3" />

This is exactly how I have my project setup.这正是我的项目设置方式。how to implement NLOG如何实现NLOG

Just additionally I am also storing Logs in File like so:另外,我还像这样将日志存储在文件中:

    <target xsi:type="File" name="fileTarget" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />

The file gets the logs however the database receives nothing.该文件获取日志,但数据库什么也没收到。 It was working prior to upgrade from .NET 5 to 6 and upgraded NLOG.它在从 .NET 5 升级到 6 并升级 NLOG 之前工作。 Anyone know of any changes that I am unaware of?有人知道我不知道的任何变化吗?

Internal errors gives me nothing but it forwarded the logs to both file and database.内部错误除了将日志转发到文件和数据库外什么也没给我。

2022-09-07 08:41:53.3680 Debug Logger Microsoft.AspNetCore.DataProtection.TypeForwardingActivator [Trace] => dbTarget
2022-09-07 08:41:53.3680 Debug Logger Microsoft.AspNetCore.DataProtection.TypeForwardingActivator [Debug] => dbTarget
2022-09-07 08:41:53.3680 Debug Logger Microsoft.AspNetCore.DataProtection.TypeForwardingActivator [Info] => dbTarget
2022-09-07 08:41:53.3680 Debug Logger Microsoft.AspNetCore.DataProtection.TypeForwardingActivator [Warn] => dbTarget fileTarget
2022-09-07 08:41:53.3680 Debug Logger Microsoft.AspNetCore.DataProtection.TypeForwardingActivator [Error] => dbTarget fileTarget
2022-09-07 08:41:53.3680 Debug Logger Microsoft.AspNetCore.DataProtection.TypeForwardingActivator [Fatal] => dbTarget fileTarget

I have same issue,我有同样的问题,

In my case, I add Nlog.DataBase from nuget management就我而言,我从 nuget 管理添加 Nlog.DataBase

and log can write to database well并且日志可以很好地写入数据库

Do not need modify any settings不需要修改任何设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM