我一直在尝试让 Nlog 将日志记录发送到数据库,但我发现的示例都返回内部 nlog 错误。我在 .NET 5.0 的控制台应用程序中使用依赖项注入...:
Info Adding target ConsoleTarget(Name=console)
Warn Error has been raised. Exception: NLog.NLogConfigurationException: Failed to create Target of type: Database
---> System.ArgumentException: Target cannot be found: 'Database'. Extension NLog.Database not included?
at NLog.Config.Factory`2.CreateInstance(String itemName)
at NLog.Config.LoggingConfigurationParser.FactoryCreateInstance[T](String classType, INamedItemFactory`2 factory)
--- End of inner exception stack trace ---
Warn Error has been raised. Exception: NLog.NLogConfigurationException: Target 'dbTarget' not found for logging rule: *.
Run Code Online (Sandbox Code Playgroud)
在我的 json 中,我有以下内容:
"NLog": {
"internalLogLevel": "info",
"internalLogFile": "${basedir}/logs/internal-nlog.txt",
"extensions": {
"NLog.Extensions.Logging": …Run Code Online (Sandbox Code Playgroud)