Send ELMAH output through NLog
I'm currently using NLog to log securi开发者_JS百科ty events from my ASP.NET MVC3 application.
Now we have another requirement to add application errors into a separate log.
Since we're already using NLog (and loving the flexibility of the Targets), I would like to configure Elmah to pass errors on to NLog for logging.
Has anyone done this & care to share?
The same request is written for Log4Net in a blog
I have translated it to NLog and updated it to NLog's recommendation:
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);
}
}
register in web.config
<elmah>
<errorLog type="MyAssembly.NLogErrorLog, MyAssembly" logPath="~/App_Data" />
</elmah>
精彩评论