我想使用Health Monitoring来记录我在自己的错误处理程序中捕获的未处理异常:
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。
答案 0 :(得分:0)
好的,所以因为在我的情况下提出让AppFabric正常工作的说明可能有些多余,我将发布一些有用的链接。
您需要做的第一件事是在AppServer Fabric配置应用程序中配置监控数据库 - 在Windows程序下。
设置:在@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。
如果您遇到任何问题,请告诉我,我会尽可能多地帮助您!