web.config
: <traceAreas>
<add provider="ASP" verbosity="Verbose" />
<add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
<add provider="ISAPI Extension" verbosity="Verbose" />
<add provider="WWW Server" areas="Security" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="200-999" />
webrole.cs
public override bool OnStart()
{
//Get Default Config
DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();
//IIS Logs
config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
Trace.WriteLine("WAD Monitor started", "Information");
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
RoleEnvironment.Changing += RoleEnvironmentChanging;
return base.OnStart();
}
我可以获得wad-iis-logsfiles
blob,但我无法在我的模拟器上获得wad-iis-failedreqlogfiles
blob
为什么自200-999以来包括所有请求!
并且应该有一个日志文件。
答案 0 :(得分:1)
好吧,我所做的是在WebRole文件中设置我的设置,我添加到web.config的代码就是这个配置
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<tracing>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="ASP" verbosity="Verbose" />
<add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
<add provider="ISAPI Extension" verbosity="Verbose" />
<add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module" verbosity="Verbose" />
</traceAreas>
<failureDefinitions verbosity="Warning" statusCodes="400-599" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
然后我使用此配置实现Onstart方法。
public override bool OnStart()
{
String wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString));
RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = cloudStorageAccount.CreateRoleInstanceDiagnosticManager(
RoleEnvironment.DeploymentId,
RoleEnvironment.CurrentRoleInstance.Role.Name,
RoleEnvironment.CurrentRoleInstance.Id);
DiagnosticMonitorConfiguration config = roleInstanceDiagnosticManager.GetCurrentConfiguration();
//Add Events
config.WindowsEventLog.DataSources.Add("System!*");
config.WindowsEventLog.DataSources.Add("Application!*");
config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Error;
config.WindowsEventLog.ScheduledTransferPeriod =TimeSpan.FromSeconds(15.0);
config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
config.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(15.0);
//transfer the IIS and IIS Failed Request Logs
config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
roleInstanceDiagnosticManager.SetCurrentConfiguration(config);
return base.OnStart();
}
我还建议您检查WerRole设置上的ConnectionString,它应该如下所示:
“DefaultEndpointsProtocol = HTTP;帐户名=我的账户; AccountKey = 8zTMPlQ8N76cEUNGLYhIvPf8lDmmTnCm7BICX / xtPmdr9vN7elOvZS5N2njtg + tbStoCoe30doN0sCrE1LHcsd ==”
或
“UseDevelopmentStorage = true”
如果您想开发您的开发环境
此外,您可以查看此网站了解更多详情
http://robindotnet.wordpress.com/2011/02/16/azure-toolssdk-1-3-and-iis-logging/
答案 1 :(得分:0)
最后我找到了答案! 这是因为IIS applicationHost会自动禁用跟踪日志文件。 当我将此代码添加到webrole.cs并输入无效的URL时,它可以工作!
using (ServerManager serverManager = new ServerManager())
{
Configuration iisConfig = serverManager.GetApplicationHostConfiguration();
ConfigurationSection sitesSection = iisConfig.GetSection("system.applicationHost/sites");
ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults");
ConfigurationElement logFileElement = siteDefaultsElement.GetChildElement("logFile");
logFileElement["enabled"] = true;
serverManager.CommitChanges();
}