詳細概論WCF性能計數器啟用問題
WCF框架是一個比較復雜的開發工具,我們需要從實踐中不斷的去探索其中的功能應用。其中WCF性能計數器是一個可以幫助我們衡量應用程序性能的集合。#t#
您可以通過 WCF 服務的 app.config 配置文件啟用WCF性能計數器,如下所示:
- < configuration>
- < system.serviceModel>
- < diagnostics performance
Counters="All" /> - < /system.serviceModel>
- < /configuration>
可以將 performanceCounters 屬性設置為啟用特定類型的性能計數器。有效值為
All:啟用所有類別計數器(ServiceModelService、ServiceModelEndpoint 和 ServiceModelOperation)。
ServiceOnly:僅啟用 ServiceModelService 類別計數器。
Off:禁用 ServiceModel* 性能計數器。這是默認值。
如果要啟用所有WCF性能計數器,則可以將配置設置放置到 Machine.config 文件中。有關在計算機上為性能計數器配置足夠內存的更多信息,請參見“增加性能計數器的內存大小”(可能為英文網頁)一節。
還可以在代碼中啟用WCF性能計數器,如下所示:
- using System.Configuration;
- using System.ServiceModel.
Configuration;- using System.ServiceModel.
Diagnostics;- Configuration config =
ConfigurationManager.OpenExe
Configuration(- ConfigurationUserLevel.None);
- ServiceModelSectionGroup sg =
ServiceModelSectionGroup.
GetSectionGroup(config);- sg.Diagnostic.PerformanceCounters =
PerformanceCounterScope.All;- config.Save();