Logging in with Elmah for WCF Web Services

We use the approach described below to log our webservice errors with Elmah. And it really works, but unfortunately the username recorded in the log is empty.

We did some debugging and found that when registering errors in ErrorHandler it HttpContext.Current.Userhas the correct user set.

We also tried:

HttpContext context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(pError, context));

and

ErrorLog.GetDefault(null).Log(new Error(pError));

Without success.

Any ideas on how we can get Elmah to register a username?

In the side signal when registering an error directly with the Webservice, the user name is registered as expected. But this approach is not very harsh.

+5
2

Elmah Thread.CurrentPrincipal.Identity.Name, HttpContext.Current.User.

Elmah, HttpContext.Current.User.

+4

, . , , ELMAH, ELMAH .

User ErrorLog_Filtering -method:

void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs args)
{
    var httpContext = args.Context as HttpContext;
    if (httpContext != null)
    {
        var error = new Error(args.Exception, httpContext);
        error.User = httpContext.User.Identity.Name;
        ErrorLog.GetDefault(httpContext).Log(error);
        args.Dismiss();
    }
}
+2

All Articles