0

我编写了一小段代码,通过单击不同的按钮,将收集不同类型的日志记录数据。但是,当我运行这段代码时,通常在通过服务器资源管理器检查时不会反映记录的数据,即使它们已记录,也可以在很长一段时间(15-20 分钟)后查看它们。我在编写这段代码时是否犯了任何错误。这段代码如下:

    DiagnosticMonitorConfiguration diagMonitorConfiguration;
    RoleInstanceDiagnosticManager roleInstanceDiagnosticManager;
    protected void Page_Load(object sender, EventArgs e)
    {


        // Get the default initial configuration for DiagnosticMonitor.
        diagMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();

        // Configures the transfer period for basic windows azure logs 
        diagMonitorConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(10);

        // Configures the log type to be Verbose
        diagMonitorConfiguration.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

        // Start the diagnostics monitor
        //DiagnosticMonitor.Start(CloudStorageAccount.DevelopmentStorageAccount, diagConfig);

        //CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));

        CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
        roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id);

        //DiagnosticMonitorTraceListener tmpListener = new DiagnosticMonitorTraceListener();
        //System.Diagnostics.Trace.Listeners.Add(tmpListener);
    }

    // Used to trace custom warning messages
    protected void btnWarning_Click(object sender, EventArgs e)
    {
        // tracing user message as a warning
        System.Diagnostics.Trace.TraceWarning("WARNING ENCOUNTERED :" + TextBoxName.Text);
    }

    // tracing custom error messages 
    protected void btnError_Click(object sender, EventArgs e)
    {
        // To log the user message as an error
        .......TraceError("ERROR ENCOUNTERED :" + TextBoxName.Text);
    }

    // tracing custom information messages
    protected void btnInformation_Click(object sender, EventArgs e)
    {
        // To log the user message as mere information
        .........TraceInformation("INFORMATION SENT :" + TextBoxName.Text);
    }

    // used to enable diagnostic infrastructure logs to be collected
    protected void btnEnableInfrastructure_Click(object sender, EventArgs e)
    {
        // configuring the type and transfer period for the Infrastructure logs
        diagMonitorConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = some filter;
        diagMonitorConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = SOME TIME PERIOD            
        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);

    }

    // used to enable crash dumps for the application
    protected void btnEnableCrashDumps_Click(object sender, EventArgs e)
    {
        //enabling crash dumps
        CrashDumps.EnableCollection(true);

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }

    // used to enable the collection windows event logs
    protected void btnEnableEventLogs_Click(object sender, EventArgs e)
    {
        //Configuring the Windows Event logs
        diagMonitorConfiguration.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

        // two types of events, application and system data are logged
        diagMonitorConfiguration.WindowsEventLog.DataSources.Add("some source");

        // the time interval is configured as 5 seconds
        diagMonitorConfiguration.WindowsEventLog.ScheduledTransferPeriod = some time period;

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }

    protected void btnEnablePerfCounters_Click(object sender, EventArgs e)
    {

        // configuring the performance counter data to be collected. processor time is collected
        diagMonitorConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
        {
            THE REQD PARAMETERS
        });

        // similarly available memory data is also logged
        diagMonitorConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
        {
            THE REQD PARAMETERS
        });

        // the scheduled time transfer is configured to 5seconds
        diagMonitorConfiguration.PerformanceCounters.ScheduledTransferPeriod = some time period;

        //DiagnosticMonitor.Start(CloudStorageAccount.DevelopmentStorageAccount, diagConfig);  USED PREVIOUSLY

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }
}
4

3 回答 3

2

IIRC,1 分钟似乎是最短传输时间。如果您将其设置为较小的值,则不完全确定会发生什么。您可以检查生成的控制文件(在 wad-control 容器中)并查看实际设置的传输速率。请记住,这是一个异步过程(日志、本地缓冲区,然后传输)。如果您想要实时的东西,您需要调整跟踪侦听器以直接记录到表或 blob(或使用服务总线跟踪)。 查看有关调试的培训工具包,了解如何做到这一点。

于 2011-08-05T16:14:02.847 回答
1

根据文档

ScheduledTransferPeriod 属性用于设置数据缓冲区将本地日志记录数据传输到持久存储的频率。默认情况下,不会为任何数据缓冲区设置此属性,以防止意外存储成本。

您为此属性设置的值将四舍五入到最接近的分钟。因此,您可以指定的最短传输时间为 1 分钟。

于 2011-08-06T12:13:09.100 回答
0

不能肯定地说,但你有多次调用SetCurrentConfiguration(). 上次我检查时,您只能调用一次。我不知道通过多次调用它会看到什么观察到的行为。我真的建议将所有诊断配置代码聚合到一个地方,可能在 global.asax 中,而不是分散在几个按钮处理程序中。

于 2011-08-06T14:38:05.940 回答