【问题标题】:Send ELMAH output through NLog通过 NLog 发送 ELMAH 输出
【发布时间】:2011-10-05 21:03:16
【问题描述】:

我目前正在使用 NLog 从我的 ASP.NET MVC3 应用程序中记录安全事件。

现在我们需要将应用程序错误添加到单独的日志中。

由于我们已经在使用 NLog(并且喜欢 Targets 的灵活性),我想配置 Elmah 以将错误传递给 NLog 进行日志记录。

有人做过这个并愿意分享吗?

【问题讨论】:

  • 看到this answer类似的问题
  • @MarnixvanValen 该答案解释了如何将错误从 NLog 传递给 Elmah。问题是关于将 Elmah 异常传递给 NLog。

标签: elmah nlog


【解决方案1】:

blog 中为 Log4Net 编写了相同的请求

我已经把它翻译成NLog并更新到NLog的推荐:

public class NLogErrorLog : XmlFileErrorLog
{
    private static Logger logger = LogManager.GetLogger("elmah");

    public NLogErrorLog(IDictionary config) : base(config)
    {
    }


    public NLogErrorLog(string logPath) : base(logPath)
    {
    }

    public override string Log(Error error)
    {
        //Write whatever you want to NLog
        logger.Error(error.Exception, "Exception logged through ELMAH: " + error.Message);
        return base.Log(error);
    }
}

在 web.config 中注册

<elmah>  
    <errorLog type="MyAssembly.NLogErrorLog, MyAssembly" logPath="~/App_Data" />  
</elmah>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 2015-12-08
    • 2017-09-28
    • 2012-03-30
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多