我正在尝试运行azure角色 - 它在模拟器上运行,但在Azure上运行。所以我尝试将Tracing集成到我的项目中。我首先尝试了一个简单的测试项目(完美的工作),但在我的“真实”项目中,我没有得到结果。
以下是我的文件:
的app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
</configuration>
ServiceConfiguration.Cloud.cscfg
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="MyServiceName" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="3" osVersion="*" schemaVersion="2013-03.2.0">
<Role name="MyRoleName">
<Instances count="2" />
<ConfigurationSettings>
<Setting name="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=<myAccount>;AccountKey=<myKEy==>" />
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=<myAccount>;AccountKey=<myKEy==>" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
ServiceDefinition.csdef中
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MyServiceName" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2013-03.2.0">
<WorkerRole name="MyRoleName" vmsize="Small">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InternalEndpoint name="InternalEndpoint1" protocol="tcp" />
</Endpoints>
<ConfigurationSettings>
<Setting name="StorageConnectionString" />
</ConfigurationSettings>
</WorkerRole>
</ServiceDefinition>
我的源代码(代码段):
public override bool OnStart()
{
ConfigDiagnostics();
Trace.TraceInformation("Initializing storage account");
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
return base.OnStart();
}
private void ConfigDiagnostics()
{
DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();
config.ConfigurationChangePollInterval = TimeSpan.FromMinutes(1d);
config.Logs.BufferQuotaInMB = 500;
config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1d);
//DiagnosticMonitor.Start(@"StorageConnectionString", config);
DiagnosticMonitor.Start(@"Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
}
相同的代码在一个简单的新Azure项目中工作 - 但不在此项目中。我现在能看到的唯一区别是:我的“真实”项目在我的run()方法中引发异常。可能是我的跟踪结果(来自Trace.WriteLine或Trace.TraceError或Trace.TraceInformation)没有上传,因为天蓝色实例的异常和回收发生得太快/太早,无法将我的跟踪结果上传到我的存储帐户?或者我可能错过了另一个观点?!
最好的问候:)
答案 0 :(得分:0)
问题是另一个问题:使用cspack打包azure角色并使用Visual Studio打包azure角色会产生影响,加上我在包文件中打包角色的命令是愚蠢的。
跟踪本身就像我上面那样完美。