【问题标题】:View Worker Role trace lines and log files查看 Worker Role 跟踪行和日志文件
【发布时间】:2012-05-06 13:04:44
【问题描述】:

我有.Net Worker 角色 (Azure),我的应用程序以这种形式写入本地日志文件:

StreamWriter sw = File.AppendText("aaa.log");
sw.WriteLine("Error occured"");
sw.Close();

我怎样才能看到这个日志文件?

【问题讨论】:

标签: c# logging azure cloud azure-worker-roles


【解决方案1】:

这是您提出的上述问题的直接答案:

  • 如果您只是从模板创建一个空白的 Windows Azure Worker Role 并在 OnStart() 函数中准确添加上述代码,然后在 Compute Emulator 中测试您的应用程序:

    public override bool OnStart()
    {
        // Set the maximum number of concurrent connections 
        ServicePointManager.DefaultConnectionLimit = 12;
        StreamWriter sw = File.AppendText("aaa.log");
        sw.WriteLine("Error occured");
        sw.Close();
    
        return base.OnStart();
    }
    
  • 您将看到 aaa.log 文件在以下位置创建,您可以匹配文件夹详细信息,因为我的测试应用程序名称是“TestWorkerRole”:

    _your_drive_and_Folder_path\TestWorkerRole\TestWorkerRole\csx\Debug\roles\WorkerRole1\approot\aaa.log

  • 我还可以验证它是否也包含文本“发生错误”,因此代码按预期执行。

  • 当您将完全相同的应用程序部署到 Windows Azure 时,代码将运行,您会发现在以下位置生成了相同的 aaa.log 文件:

    E:\approot\bin

上述方法是否正确,根本不正确,您不能使用它,主要原因如下:

  • Windows Azure VM 没有持久化,因此您创建的任何内容以后都可能无法使用,因此您必须有办法移动数据
  • Windows Azure 提供了一种在应用程序中添加诊断的特定方法,其中所有日志都创建在 Windows Azure VM 中的特定固定位置,然后根据您的设置(Azure 存储和传输日志的时间),这些日志是从 Azure VM 转移到您的 Windows Azure 存储。
  • 您必须使用 Windows Azure 诊断方法来添加以下链接中描述的任何自定义日志方法:

http://msdn.microsoft.com/en-us/library/hh180875.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 2021-02-15
    • 2011-12-21
    相关资源
    最近更新 更多