小编Dav*_*veM的帖子

Nlog 使用 DI 并使用 appsettings.json 记录到数据库 .NET 5.0

我一直在尝试让 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)

c# nlog

7
推荐指数
1
解决办法
7687
查看次数

标签 统计

c# ×1

nlog ×1