1

我用这个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-logsfilesblob,但我无法wad-iis-failedreqlogfiles在我的模拟器上得到 blob 为什么自 200-999 以来包含所有请求!并且应该有一个日志文件。

4

2 回答 2

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;AccountName=myAccount;AccountKey=8zTMPlQ8N76cEUNGLYhIvPf8lDmmTnCm7BICX/xtPmdr9vN7elOvZS5N2njtg+tbStoCoe30doN0sCrE1LHcsd=="

或者

“UseDevelopmentStorage=true”

如果你想在你的开发环境中工作

您也可以查看此站点以获取更多详细信息

http://robindotnet.wordpress.com/2011/02/16/azure-toolssdk-1-3-and-iis-logging/

于 2012-10-26T17:46:08.020 回答
0

终于我找到了答案!这是因为 IIS applicationHost 自动禁用跟踪日志文件。当我将此代码添加到 webrole.cs 并输入无效的网址时,它可以工作!

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();
        }
于 2012-11-13T07:11:48.247 回答