代码和配置:
我已经按照https://www.windowsazure.com/en-us/develop/net/common-tasks/diagnostics/上的官方教程启用了诊断。我的诊断初始化程序是从 Global.asax 调用的(此 WCF 没有 WebRole.cs 移植到 Azure WebRole),它非常简单,例如:
public bool Initialize()
{
DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();
config.WindowsEventLog.DataSources.Add("Application!*");
config.WindowsEventLog.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1.0);
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
return true;
}
云和本地字符串相同:
我正在使用基于相同云的诊断连接字符串local
和cloud
配置。
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="MyApp.API.Azure1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*" schemaVersion="2012-05.1.7">
<Role name="MyApp.API">
<Instances count="1" />
<ConfigurationSettings>
...
<Setting name="Microsoft.WindowsAzure.Plugins.Caching.ConfigStoreConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myapi;AccountKey=MyVeryLongStringHereWhichIsActuallyAKeyForAPlaceInTheCloudWhereUnicornsDanceUnderDoubleRainbows" />
</ConfigurationSettings>
<Certificates>
<Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="ThumbPrintStringsAreBiggerThanPinkiePrintString" thumbprintAlgorithm="sha1" />
</Certificates>
</Role>
</ServiceConfiguration>
错误:
当我在 Azure 模拟器(本地计算)中运行上述内容时,我没有收到错误消息(尽管有用于诊断的云连接字符串)。当我在 Azure 上运行 webrole 时(使用相同的诊断信息,当然还有代码),我收到以下错误:
[UnauthorizedAccessException: Access to the path '05d5e525-e1bc-4a37-8bfb-010bb2941301-mswapd-lock' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12895415
System.Threading.MutexTryCodeHelper.MutexTryCode(Object userData) +229
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0
System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean& createdNew, MutexSecurity mutexSecurity) +629
System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean& createdNew) +18
Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.StartDiagnosticsMonitorProcess(DiagnosticMonitorStartupInfo info) +171
Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.ReconfigureMonitoringProcess(ConfigRequest req) +209
Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.UpdateState(DiagnosticMonitorStartupInfo startupInfo) +207
Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.StartWithExplicitConfiguration(DiagnosticMonitorStartupInfo startupInfo, DiagnosticMonitorConfiguration initialConfiguration) +643
Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.Start(CloudStorageAccount storageAccount, DiagnosticMonitorConfiguration initialConfiguration) +47
Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.Start(String diagnosticsStorageAccountConfigurationSettingName, DiagnosticMonitorConfiguration initialConfiguration) +108
myApp.api.Diag.Diagnostics.Initialize() in c:\Work\MyApp.API\source\Diag\Diagnostics.cs:42
Global.Application_Start(Object sender, EventArgs e) in c:\Work\MyApp.API\source\Global.asax.cs:30
尝试:没有成功
- 禁用此存储帐户的所有 Azure 监控和日志记录(来自门户),以防 Azure 自己的监控/日志记录机制将其锁定
- 即使对于本地配置(本地计算/Azure 模拟器),也已替换
UseDevelopmentStorage=true
为用于诊断的真实云连接字符串。 - 将诊断初始化程序简化为最低限度(见上文)。然而,
DiagnosticMonitor.Start(...)
总是失败。 - 在 .cscfg 文件中创建了另一个诊断连接字符串(在 .csdef 中也有参考),这样如果
Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString
Azure 基础结构也使用原始连接字符串,我就有另一个字符串。没有帮助,同样的错误。
我花了很多时间试图调试它,但我总是在 Azure 上得到这个错误。
问题:
有人可以帮我摆脱这个错误吗?我可以尝试一些你可能有的想法。我对 MS 教程感到失望,但失望无济于事。