我用Elmah.XmlFileErrorLog 尝试了这个解决方案但是我遇到了异常
System.ArgumentNullException was unhandled by user code
Message="Value cannot be null.\r\nParameter name: context"
Source="Elmah"
ParamName="context"
StackTrace:
at Elmah.ErrorSignal.FromContext(HttpContext context) in c:\builds\ELMAH\src\Elmah\ErrorSignal.cs:line 67
at Elmah.ErrorSignal.FromCurrentContext() in c:\builds\ELMAH\src\Elmah\ErrorSignal.cs:line 61
at ElmahHttpErrorHandler.ProvideFault(Exception error, MessageVersion version, Message& fault) in c:\Myapplication\App_Code\Util\ElmahHttpErrorHandler.cs:line 19
at System.ServiceModel.Dispatcher.ErrorBehavior.ProvideFault(Exception e, FaultConverter faultConverter, ErrorHandlerFaultInfo& faultInfo)
at System.ServiceModel.Dispatcher.ErrorBehavior.ProvideMessageFaultCore(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessageCleanup(MessageRpc& rpc)
InnerException:
Run Code Online (Sandbox Code Playgroud)
Web.Config文件
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, …Run Code Online (Sandbox Code Playgroud) 我们正在开发一个3层应用程序,我们已被允许使用最新和最好的(MVC2,IIS7.5,WCF,SQL2k8等).WCF服务将应用程序层公开给各种Web应用程序.由于我们控制服务和客户端,因此我们决定使用net.tcp绑定来提高其在HTTP上的性能优势.
我们希望使用ELMAH进行错误记录,包括Web应用程序和服务.这是我的问题.有很多关于将ELMAH与WCF一起使用的信息,但它都适用于HTTP绑定.有谁知道是否/如何使用ELMAH与WCF服务暴露非HTTP端点?
我的猜测是否定的,因为ELMAH需要HttpContext,它需要在web.config 中将AspNetCompatibilityEnabled标志设为true.来自MSDN:
IIS 7.0和WAS允许WCF服务通过HTTP以外的协议进行通信.但是,不允许在启用ASP.NET兼容模式的应用程序中运行的WCF服务公开非HTTP端点.当服务接收到其第一条消息时,这种配置会生成激活异常.
如果您不能将ELMAH与具有非HTTP端点的WCF服务一起使用,那么后续问题是:我们能否以不需要HttpContext的方式使用ELMAH?或者更一般地说(为了不提交细金属标尺错误),有没有办法将ELMAH与具有非HTTP端点的WCF服务一起使用?
注意:我知道我们可以下载Elmah源代码并将其更改为添加填充程序或删除HttpContext依赖项,但我正在尝试避免分叉代码.
我们使用此处描述的方法使用Elmah记录我们的Web服务错误.这实际上是有效的,但遗憾的是,记录的用户名是空的.
我们做了一些调试,发现当在ErrorHandler中记录错误时,它HttpContext.Current.User具有正确的用户设置.
我们还尝试过:
HttpContext context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(pError, context));
Run Code Online (Sandbox Code Playgroud)
和
ErrorLog.GetDefault(null).Log(new Error(pError));
Run Code Online (Sandbox Code Playgroud)
没有成功.
关于我们如何让Elmah记录用户名的任何想法?
在旁注中,当直接在Webservice中记录错误时,将按预期记录用户名.但采取这种方法并不是很干.