We had been a purely Log4Net shop until Log4net stopped logging for us in production on numerous occasions. To circumvent this from happening we decided to implement ELMAH for our entire application (even for basic logging). We could not be happier with the results as all of our log statements appear in one spot and there are no more text files to traverse (unless we wanted to traverse the XML files). We kept Log4Net around for one more iteration, but finally found it to be of little use and have completely removed it from our application.
I can see why you might want to have two different logging frameworks for a site, especially since ELMAH requires an HttpContext in order to work to its full potential. However, we did find a way to pass the exception to ELMAH without an HttpContext:
/// <summary>
/// Main logger method that will log an exception and/or a message
/// </summary>
/// <param name="exception">Exception to log</param>
/// <param name="message">Message to log</param>
private static void Log(Exception exception, string message)
{
Error elmahError = exception != null ? new Error(exception) : new Error();
if (!string.IsNullOrWhiteSpace(message))
{
elmahError.Message = message;
}
Elmah.ErrorLog.GetDefault(null).Log(elmahError);
}
Then in your web.config you just need to specify the applicationName
:
<elmah>
<security allowRemoteAccess="1" />
<errorLog name="ELMAHLogger" applicationName="xxx" type="Elmah.XmlFileErrorLog, Elmah" logPath="~/ELMAH_Production_Logs" />
</elmah>
Again, I think Log4Net is a fine logging framework and it worked for us for a number of years. I find ELMAH to be easier to use when looking for an exception and the above code has allowed us to use it anywhere in our application where the HttpContext might not be available.