1

I have .Net Worker role (Azure) and my application write to local log files in this form:

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

How can I see this log file ?

the-ginger-geek
  • 7,041
  • 4
  • 27
  • 45
Tal Yaari
  • 463
  • 6
  • 15

1 Answers1

5

Here is the direct answer to your above question as you presented:

  • If you just create a blank Windows Azure Worker Role from template and add above code exactly in the OnStart() function and then test your application in 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();
    }
    
  • You will see the aaa.log file is created in the location below and you can match the folder details as my test application name is "TestWorkerRole":

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

  • I can also verify that it has the text "Error occurred" also in it so the code executed as it supposed to.

  • When you will deploy the exact same application to Windows Azure, the code will run and you will find the same aaa.log file is generated at:

    E:\approot\bin

Is above approach is correct, NOT AT ALL and you must not use it, due to following main reasons:

  • Windows Azure VM are not persisted so anything you create may not available later so you must have a way to move your data
  • Windows Azure provide a specific way to add diagnostics in your application in which the all the logs are created a specific fixed location in your Windows Azure VM and then based in your setting (Azure storage and time to transfer logs) these logs are transferred from Azure VM to your Windows Azure Storage.
  • You must use Windows Azure Diagnostics method to add any custom log method which is described in link below:

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

AvkashChauhan
  • 20,495
  • 3
  • 34
  • 65