locked
Windows Azure logging in different tables RRS feed

  • Question

  • I have an Azure Worker Role that generates a lot of log data. In order to manage this better i want to write logs in different tables not just in WADLogsTable. Can I do this with DiagnosticMonitorTraceListener or do i need to write explicit code for creating new tables and writing to them. Maybe there is another way.

    I now write logs like this :

    var traceListener = new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener();
    traceListener.WriteLine(message, level);

    Please help.

    Thursday, May 12, 2011 3:24 PM

Answers

  • Hello SorinBolos,

    Indead of writting logs in different tables, we can write our logs into file system by using the LocalStorage feature and then configure DiagnosticMonitor to transfer the log files to azure stroage.

    To do this, please define a local resource in ServiceDefinition.csdef file:

        <LocalResources>
          <LocalStorage name="LocalStorage1" cleanOnRoleRecycle="false" sizeInMB="100" />
        </LocalResources>

    Then in OnStart method of your RoleEntryPoint class, please input the following code:

    public override bool OnStart()
    {
        var traceResource = RoleEnvironment.GetLocalResource("LocalStorage1");
        var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
        config.Directories.DataSources.Add(
            new DirectoryConfiguration
            {
                Path = traceResource.RootPath,
                Container = "mytraces",
                DirectoryQuotaInMB = 100
            });
        config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

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

        // Write log.
        string logFilePath = RoleEnvironment.GetLocalResource("LocalStorage1").RootPath + "Hello.txt";
        TextWriterTraceListener traceListener = new TextWriterTraceListener(logFilePath);
        traceListener.WriteLine("Hello");
        traceListener.Flush();

        return base.OnStart();
    }

    Start degugging your azure service and wait for several minutes, please check your storage emulator and you will see a new blob container "mytraces" is created containing a blob which is the log file created by TextWriterTraceListener.

    For more information, please refer to http://weblogs.thinktecture.com/cweyer/2010/12/transferring-your-custom-trace-log-files-in-windows-azure-for-remote-inspection.html. If you need more assistance, please let me know.

    Thanks,


    Wengchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by SorinBolos Tuesday, May 17, 2011 12:40 PM
    Tuesday, May 17, 2011 6:51 AM

All replies

  • Hello SorinBolos,

    Thank you posting!

    This is a quick note to let you know that I am performing research on this issue and will get back to you as soon as possible. I appreciate your patience.

    Thanks,


    Wengchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Friday, May 13, 2011 9:53 AM
  • Hello SorinBolos,

    Indead of writting logs in different tables, we can write our logs into file system by using the LocalStorage feature and then configure DiagnosticMonitor to transfer the log files to azure stroage.

    To do this, please define a local resource in ServiceDefinition.csdef file:

        <LocalResources>
          <LocalStorage name="LocalStorage1" cleanOnRoleRecycle="false" sizeInMB="100" />
        </LocalResources>

    Then in OnStart method of your RoleEntryPoint class, please input the following code:

    public override bool OnStart()
    {
        var traceResource = RoleEnvironment.GetLocalResource("LocalStorage1");
        var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
        config.Directories.DataSources.Add(
            new DirectoryConfiguration
            {
                Path = traceResource.RootPath,
                Container = "mytraces",
                DirectoryQuotaInMB = 100
            });
        config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

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

        // Write log.
        string logFilePath = RoleEnvironment.GetLocalResource("LocalStorage1").RootPath + "Hello.txt";
        TextWriterTraceListener traceListener = new TextWriterTraceListener(logFilePath);
        traceListener.WriteLine("Hello");
        traceListener.Flush();

        return base.OnStart();
    }

    Start degugging your azure service and wait for several minutes, please check your storage emulator and you will see a new blob container "mytraces" is created containing a blob which is the log file created by TextWriterTraceListener.

    For more information, please refer to http://weblogs.thinktecture.com/cweyer/2010/12/transferring-your-custom-trace-log-files-in-windows-azure-for-remote-inspection.html. If you need more assistance, please let me know.

    Thanks,


    Wengchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by SorinBolos Tuesday, May 17, 2011 12:40 PM
    Tuesday, May 17, 2011 6:51 AM
  • Yes, that helped a lot.  Thanks. This could be a solution.
    Tuesday, May 17, 2011 12:43 PM
  • Hi,
    I have the same problem like SorinBolos had, the only difference is that I have to write logs in different tables certainly. Writing into log files in the 
    blob is not proper for me in no way. At our company, we expect lots of users and we would like to create a separate log table for all them.
       Can you offer me something, please?
    • Edited by Gabor Nagy Thursday, November 10, 2011 3:43 PM
    Thursday, November 10, 2011 3:42 PM