【问题标题】:NLog with ASP.NET CORE 2 and AspNetBufferingWrapper - error not foundNLog 与 ASP.NET CORE 2 和 AspNetBufferingWrapper - 未找到错误
【发布时间】:2018-12-22 22:35:19
【问题描述】:

我正在使用带有 NLog 的 ASP.NET CORE 2.1。我可以毫无问题地登录到电子邮件、文件和内部日志。

我想为 http 请求发送一次电子邮件,例如该请求的日志。

我读到这个 ​​AspNetBufferingWrapper 可以参考https://github.com/NLog/NLog/wiki/AspNetBufferingWrapper-target

在我的 nlog.config 中,我有以下目标......包装我的工作电子邮件目标的 aspnetbuffer。

<target xsi:type="AspNetBufferingWrapper"
     name="AspNetBufferingWrapper1"
     bufferGrowLimit="Integer"
     growBufferAsNeeded="Boolean"
     bufferSize="Integer">

  <target name="WrappedRulesEngineLogMail" xsi:type="Mail"
        smtpServer="TEST.TEST.COM"
          subject="Wrapped Rules Engine Log"              
        layout="[${longdate}] - [${machinename}] - [${level}] - [${message}] - [${exception:format=toString}]"
        from="noreply@TEST.com"
        to="ME@TEST.com"/>      
</target>

内部日志响应此错误消息

nlog.config 失败。异常:NLog.NLogConfigurationException:解析 C:\inetpub\wwwroot\IT\TEST\ACES\Main\Aces.Web\bin\Debug\netcoreapp2.1\nlog.config 时出现异常。 ---> System.ArgumentException:找不到目标:'AspNetBufferingWrapper'。不包括 NLog.Web 吗? 在 NLog.Config.Factory`2.CreateInstance(字符串名称) 在 NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLogXmlElement 目标元素) 在 NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement,字符串文件路径,布尔 autoReloadDefault) 在 NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)

为了完整起见,我将在 Program.cs 中包含我的设置

 public static IWebHost CreateDefaultBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()                
            .ConfigureLogging((context, logging) => {
                logging.ClearProviders();                    logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
                if (context.HostingEnvironment.IsDevelopment())
                {
                    logging.AddDebug();
                }
            })
            .UseNLog()  // NLog: setup NLog for Dependency injection
            .Build();

我已经加载了这些 nuget 包

不知道怎么解决 找不到目标:“AspNetBufferingWrapper”。不包括 NLog.Web 吗?在 NLog.Config.Factory`2.CreateInstance(String name)

为什么可以找到目标?

ty

【问题讨论】:

  • 我不知道您的问题的答案,但您应该修复包装器的属性,现在它们具有值的类型名称,而不是值本身......例如: growBufferAsNeeded="Boolean" => growBufferAsNeeded="true"
  • 也许你需要添加一个 nuget/PackageReference 到 NLog.Web.AspNetCore: nuget.org/packages/NLog.Web.AspNetCore - 看起来你的目标和缺少的程序集是在那里定义的
  • 是的,谢谢,我也尝试过正确设置属性。是的 NLog.Web.AspNetCore 已经包含在内。还是行不通。此刻,我不觉得是 AspNetBufferingWrapper 不适用于 asp.net 核心。我希望其他人取得更大的成功。
  • 您是否按照您提供的链接中的备注部分进行操作?看来您还需要更新 httpModules 以包含对程序集的引用。不过,您可能对它不在核心中工作是正确的。如果您阅读我之前链接的页面上的 nuget 描述,它没有提到“目标”,只是“帮助程序和布局渲染器”。如果您阅读了 asp.net 版本的描述,它明确地调用了“附加目标” .也许这是在nlog github问题中发布的内容。
  • 参见此处的讨论:github.com/NLog/NLog/issues/2806

标签: c# logging asp.net-core nlog


【解决方案1】:

这是正确的。 AspNetBufferingWrapper 在 NLog.Web 包中,而不在 NLog.Web.AspNetCore 中。

它尚未移植到 ASP.NET Core,因此仅支持 ASP.NET 非核心。

Link to feature request

【讨论】:

    猜你喜欢
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 2019-11-20
    • 1970-01-01
    • 2018-04-25
    相关资源
    最近更新 更多