I am new to ELMAH Error Logging. I have tried different option but didn't work. Following is my solution project structure. I am using ELMAH.MVC nugget package.
xyz.sol
xyz.web (mvc project)
xyz.Service (class librarry)
xyz.Data (DAL)
xyz.Model (model classes)
I have setup ELMAH in xyz.web (MVC project) and it works fine with basic testing ie. 404 error. I can see that error logged and also in url www.project-name.com/ELmah
But, I want to use ELMAH in all other class library too (Service & Data). When something fails in service layer that error never got logged in the ElMAH. I was under impression that ELMAH.mvc nuget package log all handled and unhanded exception by itself. It seems that i might be missing in configuration or i might have to configure ELMAH in class library project too.
Please advise.
Thanks
Following my global handle error filter. It reaches to OnException but never reaches to LogException Method as "RaiseErrorSignal" method always returns true. Can you please advise me what am i doing wrong?
<code>
public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{
private static ErrorFilterConfiguration _config;
public override void OnException(ExceptionContext context)
{
base.OnException(context);
if (!context.ExceptionHandled) // if unhandled, will be logged anyhow
return;
var e = context.Exception;
var httpContext = context.HttpContext.ApplicationInstance.Context;
if (httpContext != null &&
(RaiseErrorSignal(e, httpContext) // prefer signaling, if possible
|| IsFiltered(e, httpContext))) // filtered?
return;
LogException(e, httpContext);
}
private static bool RaiseErrorSignal(Exception e, HttpContext context)
{
var signal = ErrorSignal.FromContext(context);
if (signal == null)
return false;
signal.Raise(e, context);
return true;
}
private static bool IsFiltered(Exception e, HttpContext context)
{
if (_config == null)
{
_config = context.GetSection("elmah/errorFilter")
as ErrorFilterConfiguration
?? new ErrorFilterConfiguration();
}
var testContext = new ErrorFilterModule.AssertionHelperContext(e, context);
return _config.Assertion.Test(testContext);
}
private static void LogException(Exception e, HttpContext context)
{
ErrorLog.GetDefault(context).Log(new Error(e, context));
}
}
</code>