使用Elmah为WCF Webservices记录用户名 [英] Logging username with Elmah for WCF Webservices

查看:248
本文介绍了使用Elmah为WCF Webservices记录用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用此处所述的方法使用Elmah记录我们的Web服务错误。这实际上是有效的,但遗憾的是,记录的用户名为空。

We are using the approach described here to log our webservice errors with Elmah. And this actually works, but sadly the username beeing logged is empty.

我们做了一些调试,发现在ErrorHandler中记录错误时, HttpContext.Current.User 有正确的用户设置。

We did some debugging and found, that when logging the error in the ErrorHandler the HttpContext.Current.User has the correct User set.

我们还尝试过:

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

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

没有成功。

我们如何使Elmah登录用户名?

Any ideas on how we can make Elmah log the username?

在sidenote中,当直接在Webservice中记录错误时,用户名将按预期方式记录。但是采取这种方式并不是很干,

On a sidenote, when logging the error directly within the Webservice, the username is logged as expected. But taking this approach is not very DRY.

推荐答案

Elmah将用户从 Thread.CurrentPrincipal.Identity .Name 而不是从 HttpContext.Current.User

Elmah take the user from Thread.CurrentPrincipal.Identity.Name and not from HttpContext.Current.User.

一个方便的方式来添加自定义数据到Elmah,我建议重新编译代码,并调用HttpContext.Current.User。

Since there ins't a convenient way to add custom data to Elmah, I would suggest recompiling the code, and calling HttpContext.Current.User instead.

这篇关于使用Elmah为WCF Webservices记录用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆