简体   繁体   English

WCF Web服务和本机ASP.NET运行状况监视

[英]WCF Web Services and native ASP.NET Health Monitoring

I need a final answer to the following question! 我需要对以下问题给出最终答案! :-) :-)

I was wondering if you can enable Health Monitoring for WCF Web services. 我想知道您是否可以为WCF Web服务启用运行状况监视。 I'm hosting a number of services in IIS and configured it to send the team email notification when any exceptions are thrown. 我在IIS中托管了许多服务,并将其配置为在抛出任何异常时发送团队电子邮件通知。 I feel that Health Monitoring does not work with WCF Services and that I have to configure WCF Tracing http://msdn.microsoft.com/en-us/library/ms733025.aspx 我觉得Health Monitoring不能与WCF服务一起使用,我必须配置WCF跟踪http://msdn.microsoft.com/en-us/library/ms733025.aspx

Thank you 谢谢

I tried it before too, but all solutions looked too complex. 我之前也尝试过,但所有解决方案看起来都太复杂了。

I ended up just do it manually. 我最后只是手动完成。

First setup a custom WebEvent. 首先设置自定义WebEvent。 Eg: 例如:

public class SyncError : WebBaseErrorEvent
{
  public SyncError(string message, Exception e)
    : base(message, "Sync", WebEventCodes.WebExtendedBase + 1, 0, e)
  {    
  }

  public override void FormatCustomEventDetails(WebEventFormatter formatter)
  {
    base.FormatCustomEventDetails(formatter);
    formatter.AppendLine(ErrorException.ToString());
  }
}

Next use it like: 接下来使用它像:

// WCF method
public int Sync()
{
  try
  {
    // do normal stuff
  }
  catch (Exception ex)
  {
    var e = new SyncError("Error in Sync", ex);
    e.Raise();
    throw;
  }
}

Finally, modify the web.config: 最后,修改web.config:

<eventMappings>
  <add name="Sync Errors" type="SyncLibrary.SyncError, SyncLibrary"/>
</eventMappings>

<rules>
  <add name="Sync Errors SQL" eventName="Sync Errors" 
       provider="SqlWebEventProvider"
       profile="Default" 
       minInstances="1" 
       maxLimit="Infinite" 
       minInterval="00:00:00" />
</rules>

Note: this assumes you have health-monitoring turned on. 注意:这假设您已启用运行状况监控。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM