详细概论WCF性能计数器启用问题

WCF框架是一个比较复杂的开发工具,我们需要从实践中不断的去探索其中的功能应用。其中WCF性能计数器是一个可以帮助我们衡量应用程序性能的集合。#t#

您可以通过 WCF 服务的 app.config 配置文件启用WCF性能计数器,如下所示:

  1. < configuration> 
  2. < system.serviceModel> 
  3. < diagnostics performance
    Counters
    ="All" /> 
  4. < /system.serviceModel> 
  5. < /configuration> 

可以将 performanceCounters 属性设置为启用特定类型的性能计数器。有效值为

All:启用所有类别计数器(ServiceModelService、ServiceModelEndpoint 和 ServiceModelOperation)。

ServiceOnly:仅启用 ServiceModelService 类别计数器。

Off:禁用 ServiceModel* 性能计数器。这是默认值。

如果要启用所有WCF性能计数器,则可以将配置设置放置到 Machine.config 文件中。有关在计算机上为性能计数器配置足够内存的更多信息,请参见“增加性能计数器的内存大小”(可能为英文网页)一节。

还可以在代码中启用WCF性能计数器,如下所示:

 
 
 
  1. using System.Configuration;  
  2. using System.ServiceModel.
    Configuration;  
  3. using System.ServiceModel.
    Diagnostics;  
  4. Configuration config = 
    ConfigurationManager.OpenExe
    Configuration(  
  5. ConfigurationUserLevel.None);  
  6. ServiceModelSectionGroup sg = 
    ServiceModelSectionGroup.
    GetSectionGroup(config);  
  7. sg.Diagnostic.PerformanceCounters =
     
    PerformanceCounterScope.All;  
  8. config.Save(); 

 

THE END