Windows Azure Trace Log not working

前端 未结 3 1705
暖寄归人
暖寄归人 2021-02-08 05:14

I\'m sure I have missed something simple but I can\'t get simple Trace.WriteLine to work on Azure.

Steps I have taken:

Microsoft.WindowsAzure.Plugins.Diagnostics

相关标签:
3条回答
  • 2021-02-08 05:45

    I had this same problem. I was using the solution here. I believe the piece you are missing is the location where logs are scheduled to be transferred (in this case, using a LocalResource path):

    public override bool OnStart()
    {
        Trace.WriteLine("Entering OnStart...");
    
        var traceResource = RoleEnvironment.GetLocalResource("TraceFiles");
        var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
    
        // *** this part specifies where transfers should be stored ***
        config.Directories.DataSources.Add(
            new DirectoryConfiguration
            {
                Path = traceResource.RootPath,
                Container = "traces",
                DirectoryQuotaInMB = 100
            });
        config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(10);
    
        DiagnosticMonitor.Start("DiagnosticsConnectionString", config);
    
        return base.OnStart();
    }  
    

    In order for this to work, you have to create a LocalStorage node to store these files in your ServiceDefinition.csdef:

    <LocalStorage name="TraceFiles" sizeInMB="100" cleanOnRoleRecycle="true" />
    

    and you need to have a way to transfer these files to some place where you can get to them, because they are not available in the storage account, but on a local resource folder on the VM itself. I accomplish that with a webpage that allows me to download local resource files.

    0 讨论(0)
  • 2021-02-08 05:59

    Right, sorted!

    This post explains all: http://social.msdn.microsoft.com/Forums/pl-PL/windowsazuredata/thread/d3f2f1d7-f11e-4840-80f7-f61dc11742fb

    It's because in Azure SDK 1.3 upwards the listeners are different in the webrole.cs file from the rest of the web app due to it running fully in IIS. If I add trace items to the web app itself the table WADLogsTable appears with my trace information.

    0 讨论(0)
  • 2021-02-08 06:05

    I had similar problems myself, which the above posts didn't answer for me. I put together a blog post outlining the steps I took to get Diagnostics working with SDK 1.6

    Windows Azure Diagnostics with SDK 1.6 for WebRoles

    0 讨论(0)
提交回复
热议问题