Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Отвечено Logging in Windows Azure WAD using Log4Net

  • Wednesday, October 06, 2010 2:35 PM
     
     
    i want to log into WindowsAzure WADLogsTable using log4net.

All Replies

  • Wednesday, October 06, 2010 2:44 PM
     
     Proposed

    Hello,

    You must use the "log4net.Appender.TraceAppender" which is intended to "Writes logging events to the .NET trace system." The standard Windows Azure logging infrastructure is based on the .NET trace system with a Azure Trace Listener implementation.

    Hope this helps

  • Thursday, October 07, 2010 6:16 AM
     
     

    Hi-

    Thanks for reply ,I am trying to implement in same way which you have stated but still not able to log custom message in WADLog table...

    Could you help me some implementation part....

     

    Thanks in advance ...

     

  • Thursday, October 07, 2010 7:04 PM
     
     Answered Has Code

    Hello,

    First of all, you need to set the WindowsAzure trace listener in your configuration file (web.config for Web Roles, app.config for Worker roles):

     <system.diagnostics>
      <trace>
       <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
        </add>
       </listeners>
      </trace>
     </system.diagnostics>
    

    Then you need to start the Windows Azure diagnostics monitor in your OnStart() method for the role (done by default by the project template for Azure role):

          DiagnosticMonitorConfiguration diagConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
          //diagConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);
          diagConfig.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);
          diagConfig.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
    
          DiagnosticMonitor.Start("StorageClientAccount", diagConfig);
    
          // For information on handling configuration changes
          // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
          RoleEnvironment.Changing += RoleEnvironmentChanging;
    
          // This code sets up a handler to update CloudStorageAccount instances when their corresponding
          // configuration settings change in the service configuration file.
          CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
          {
            // Provide the configSetter with the initial value
            configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
    
            RoleEnvironment.Changed += (s, arg) =>
            {
              if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>()
                .Any((change) => (change.ConfigurationSettingName == configName)))
              {
                // The corresponding configuration setting has changed, propagate the value
                if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                {
                  // In this case, the change to the storage account credentials in the
                  // service configuration is significant enough that the role needs to be
                  // recycled in order to use the latest settings. (for example, the 
                  // endpoint has changed)
                  RoleEnvironment.RequestRecycle();
                }
              }
            };
          });
    
          return base.OnStart();
        }
    
    
        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
          // If a configuration setting is changing
          if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
          {
            // Set e.Cancel to true to restart this role instance
            e.Cancel = true;
          }
        }
    

    And finally, you have to either transfer logs periodically, as I do in last example, or transfer the logs on demand.

    You can read more on Windows Azure Diagnostics in the Neil's blog post: http://convective.wordpress.com/2009/12/08/diagnostics-in-windows-azure/

     

    Hope this helps

     

  • Friday, October 08, 2010 4:38 AM
     
     

    Hi Antin-

    Thanks a lot for your time and such a valuable input,Its really helpful for me ....

    Thanks again..

     


    cpsingh
  • Tuesday, October 12, 2010 1:28 AM
     
     
  • Thursday, February 23, 2012 10:54 AM
     
     

    Hi

    http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/4937172d-866f-48fc-9bdf-05ace25bd87e

    When i clicked on the above link , it shown the below message

    You are not authorized to perform this action.

    Can any one help me here.


    • Edited by chennas Thursday, February 23, 2012 10:54 AM
    •