健康监测和 WCF
我想使用运行状况监控来记录我在自己的错误处理程序中捕获的未处理的异常:
public class MyErrorHandler : IErrorHandler, IServiceBehavior
{
#region IServiceBehavior Members
public void AddBindingParameters(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection endpoints, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
{
IErrorHandler errorHandler = new VirusInfoErrorHandler();
foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
{
ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
if (channelDispatcher != null)
{
channelDispatcher.ErrorHandlers.Add(errorHandler);
}
}
}
public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
{
}
#endregion
#region IErrorHandler Members
public bool HandleError(Exception ex)
{
MyErrorEvent l_errEvt = new MyErrorEvent("Oh Noes!", this, WebEventCodes.WebExtendedBase + 2, ex);
// Always throws a "Value does not fall within the expected range" ArgumentException.
l_errEvt.Raise();
return true;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
}
#endregion
}
我目前正在使用一个非常简单的自定义 WebRequestErrorEvent:
public MyErrorEvent(string message, object eventSource, int eventCode, Exception exception)
: base(message, eventSource, WebEventCodes.WebExtendedBase + eventCode, exception)
{
}
public override void FormatCustomEventDetails(WebEventFormatter formatter)
{
if (formatter == null)
{
throw new ArgumentNullException("formatter", "Please supply a valid formatter object.");
}
try
{
base.FormatCustomEventDetails(formatter);
formatter.AppendLine("this was a bad error");
}
catch (Exception ex)
{
}
}
异常的堆栈跟踪是:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
at System.Web.HttpRequest.get_UrlInternal()
at System.Web.Management.WebRequestInformation..ctor()
at System.Web.Management.WebRequestErrorEvent.PreProcessEventInit()
at System.Web.Management.WebBaseEvent.RaiseInternal(WebBaseEvent eventRaised, ArrayList firingRuleInfos, Int32 index0, Int32 index1)
at System.Web.Management.WebBaseEvent.Raise(WebBaseEvent eventRaised)
at System.Web.Management.WebBaseEvent.Raise()
at ACME.MyErrorHandler.HandleError(Exception ex) in G:\Code\MySvc\Lib\ACME.ErrorHandler\MyErrorHandler.cs:line 78
at System.ServiceModel.Dispatcher.ErrorBehavior.HandleErrorCommon(Exception error, ErrorHandlerFaultInfo& faultInfo)
WebRequestErrorEvent 不能与 WCF 一起使用吗?我可以毫无问题地引发 WebRequestEvents,但不能引发 WebRequestErrorEvents。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,因为对我来说,提供让 AppFabric 在您的情况下工作的说明可能有些多余,所以我将发布一些有用的链接。
您需要做的第一件事是在 Windows 程序下的 AppServer Fabric 配置应用程序中配置监控数据库。
设置:在 @RonJacobs 的这个链接中——喜欢那个人,感谢 Ron 所做的一切——他提供了一些有关在 IIS 中设置所有内容的详细信息。对您来说最有趣的部分是启用端到端跟踪 - http://blogs.msdn.com/b/rjacobs/archive/2010/06/09/tracking-wcf-data-services-with-windows-server-appfabric.aspx。
故障排除:一旦您最初运行它,此链接中有一些很棒的故障排除信息 - http://www .lhotka.net/weblog/WindowsServerAppFabricAndWCFMonitoring.aspx。
如果您遇到任何问题,请告诉我,我会尽力提供帮助!
OK, so because it may be somewhat redundant for me to put up instructions for getting AppFabric working in your situation I'm going to post some helpful links instead.
The first thing you'll need to do is configure the Monitoring database in the AppServer Fabric configuration application -- under Windows Programs.
Setup: In this link by @RonJacobs -- love that guy, thanks Ron for all you do -- he gives some great detail regarding setting everything up in IIS. The most interesting piece for you will be Enable End-to-End Tracking - http://blogs.msdn.com/b/rjacobs/archive/2010/06/09/tracking-wcf-data-services-with-windows-server-appfabric.aspx.
Troubleshooting: In this link there is some great troubleshooting information once you get it running initially - http://www.lhotka.net/weblog/WindowsServerAppFabricAndWCFMonitoring.aspx.
Let me know if you run into any problems and I'll help as much as I can!