gpt4 book ai didi

azure - 如何让 azure webrole 记录所有 404

转载 作者:行者123 更新时间:2023-12-02 02:12:07 29 4
gpt4 key购买 nike

我一直在尝试为我的 MVC 项目使用 azure 进行日志记录,但到目前为止还没有取得太大成功。

我的 ServiceConfiguration.Cloud.cscfg 文件中有一个诊断连接字符串,它指向我的 Blob 存储:

   ...
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.DiagnosticsConnectionString" value="**ConectionString**" />
</ConfigurationSettings>

我的web.config已设置跟踪

    ...
<tracing>
<traceFailedRequests>
<remove path="*"/>
<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 timeTaken="00:00:15" statusCodes="400-599" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>

我的WebRole.cs

中有以下内容
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace MvcWebRole1
{
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
// Get the factory configuration so that it can be edited
DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();


// Set scheduled transfer interval for infrastructure logs to 1 minute
config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1);

// Specify a logging level to filter records to transfer

config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

// Set scheduled transfer interval for user's Windows Azure Logs to 1 minute
config.Logs.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1);


DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.DiagnosticsConnectionString", config);

//RoleEnvironment.Changing += this.RoleEnvironmentChanging;

return base.OnStart();
}
}
}

但是我没有看到任何诊断日志

Screenshot of Azure Blob Stoage

mam 文件夹仅包含一个 MACommanda.xml 和一个 MASecretvsdeploy 文件夹为空,并且wad-control-container 为每个部署都有一个文件。

我错过了什么/做错了什么吗?

我一直在尝试遵循 http://msdn.microsoft.com/en-us/library/windowsazure/gg433048.aspx 的指南特别是http://channel9.msdn.com/learn/courses/Azure/Deployment/DeployingApplicationsinWindowsAzure/Exercise-3-Monitoring-Applications-in-Windows-Azure

更新:

我发现以下内容可能是问题的一部分

IIS7 Logs Are Not Collected Properly - http://msdn.microsoft.com/en-us/library/hh134842

虽然这应该只说明 404 不工作,但故障定义为 15 秒,我的 Controller 操作中的 17 秒 sleep 应该仍会被记录

最佳答案

以下是我最终能够在 Azure Web 角色上运行所有日志记录的方法:

在 WebRole.cs 中包含以下内容:

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

// Filter the logs so that only error-level logs are transferred to persistent storage.
config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = config.Logs.ScheduledTransferLogLevelFilter =
config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

// Schedule a transfer period of 30 minutes.
config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = config.Logs.ScheduledTransferPeriod = config.WindowsEventLog.ScheduledTransferPeriod =
config.Directories.ScheduledTransferPeriod = config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

// Specify a buffer quota.
config.DiagnosticInfrastructureLogs.BufferQuotaInMB = config.Logs.BufferQuotaInMB = config.WindowsEventLog.BufferQuotaInMB =
config.Directories.BufferQuotaInMB = config.PerformanceCounters.BufferQuotaInMB = 512;

// Set an overall quota of 8GB maximum size.
config.OverallQuotaInMB = 8192;

// WindowsEventLog data buffer being added to the configuration, which is defined to collect event data from the System and Application channel
config.WindowsEventLog.DataSources.Add("System!*");
config.WindowsEventLog.DataSources.Add("Application!*");

// Use 30 seconds for the perf counter sample rate.
TimeSpan perfSampleRate = TimeSpan.FromSeconds(30D);

config.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
{
CounterSpecifier = @"\Memory\Available Bytes",
SampleRate = perfSampleRate
});

config.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
{
CounterSpecifier = @"\Processor(_Total)\% Processor Time",
SampleRate = perfSampleRate
});

config.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
{
CounterSpecifier = @"\ASP.NET\Applications Running",
SampleRate = perfSampleRate
});



// Start the DiagnosticMonitor using the diagnosticConfig and our connection string.
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString",config);


return base.OnStart();

在system.WebServer下的web.config中添加以下内容:

    <tracing>
<traceFailedRequests>
<remove path="*"/>
<add path="*">
<traceAreas>
<add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
<add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="400-599" />
</add>
</traceFailedRequests>
</tracing>

在服务定义文件中的 Web 角色下添加以下内容:

 <LocalResources>
<LocalStorage name="DiagnosticStore" sizeInMB="8192" cleanOnRoleRecycle="false"/>
</LocalResources>

这应该启用 MVC 应用程序中的所有日志记录。

关于azure - 如何让 azure webrole 记录所有 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12278572/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com