我有一個Azure WebRole,我正嘗試使用DiagnosticMonitor配置日誌記錄。爲什麼在使用RoleEntryPoint時無法訪問Application_Start中的RoleEnvironment?
根據在windowsazure.com測井應的OnStart來實現的文檔:
Note: The code in the following steps is typically added to the OnStart method of the role.
https://www.windowsazure.com/en-us/develop/net/common-tasks/diagnostics/
爲了訪問OnStart方法我必須定義一個RoleEntryPoint。但一旦定義,我就無法訪問Web應用程序Application_Start中的RoleEnvironment。
如何使角色環境可用於應用程序,同時仍能夠使用DiagnosticMonitor?
我將應用程序連接字符串存儲在服務配置中。
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
// config
var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
LocalResource localResource = RoleEnvironment.GetLocalResource("MyCustomLogs");
DirectoryConfiguration dirConfig = new DirectoryConfiguration();
dirConfig.Container = "wad-mycustomlogs-container";
dirConfig.DirectoryQuotaInMB = localResource.MaximumSizeInMegabytes;
dirConfig.Path = localResource.RootPath;
DiagnosticMonitorConfiguration diagMonitorConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagMonitorConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
diagMonitorConfig.Directories.DataSources.Add(dirConfig);
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
return base.OnStart();
}
什麼,當你試圖在Web應用程序的Application_Start訪問RoleEnvironment發生什麼呢? – 2012-03-29 12:47:41
這似乎與這個http://stackoverflow.com/a/6202411/348841有什麼關係,但有人可以解釋我應該怎麼做? – 2012-03-29 12:49:39
您是否試圖從Application_Start(重新)配置您的DiagnosticsMonitor? – 2012-03-29 12:49:53