0

By default Elmah obviously logs the user name as part of its log entries. Our costumer sees this as sensible data and wants it removed. How can this be done?

(By the way: There also is the "Code" field in the logs. Its always empty. What does this field mean?)

Jer
  • 383
  • 3
  • 17

1 Answers1

1

Add the following to Global.asax:

void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs args)
{
    var httpContext = args.Context as HttpContext;
    if (httpContext != null && httpContext.Request.User.Identity.IsAuthenticated)
    {
        var error = new Error(args.Exception, httpContext);
        error.User = "***hidden***";
        ErrorLog.GetDefault(httpContext).Log(error);
        args.Dismiss();
    }
}

Adapted from: http://docs.elmah.io/remove-sensitive-form-data/

EDIT

To answer you other question, the "Code" field should be the HTTP status code: 500, 404, etc.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • One minor remark: `httpContext.Request.User` doesn't exist. But the solution itself works great! But I still wonder why _Code_ is always 0 in my Elmah-log. If it's the HTTP-Code it should be different. – Jer Nov 16 '15 at 11:21