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.

Proposed Log4net in Azure

All Replies

  • Friday, February 11, 2011 12:56 PM
     
      Has Code

    Hi,

    If you use an log4net appender that writes to the diagnosticsonly, you can configure you log4net straight from code no config nessecary:

     

    This is my config which works for me:

     in your webrole:

     

     public override bool OnStart()
     {
        var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
       config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
       config.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(20);
       config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromSeconds(20);
       config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose ;
    
       DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config); 
    
       return base.OnStart();
    }
    

    in you global.asax.cs

    void Application_Start(object sender, EventArgs e)
    {
       CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSettingPublisher) =>
        {
         var connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
         configSettingPublisher(connectionString);
        }
       );
       // Code that runs on application startup
       var appender = new AzureAppender();
       appender.ActivateOptions();
       BasicConfigurator.Configure(appender);
    }
    
  • Monday, February 14, 2011 11:46 AM
     
     

    Hi prasanna,

    check the below link (need to convert the content of the link into english :))

    http://www.gine.jp/blog/taka/post/Azure-e381a6-log4net-e38292e4bdbfe38186.aspx

     

    after configurring your application you need to create a custome appender

    like this

     <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
          <layout type="log4net.Layout.PatternLayout" >
            <conversionPattern value="%-5p%d{yyyy-MM-dd hh:mm:ss} [%thread] – %m%n" />
          </layout>
        </appender>

     

    • Edited by Rahul-P Monday, February 14, 2011 11:48 AM edit
    •  
  • Thursday, February 23, 2012 9:54 AM
     
     

    Hi prasanna,

    Did you find out the solution for your problem.  If you find the solution could you please share it, We are also having similar problem, as we are moving our web application to Azure, and used log4net in the applicaiton.

    Thanks

  • Thursday, February 23, 2012 5:55 PM
     
     

    Add a trace appender to log4net which would write into the Trace and make sure you have azure diagnostics trace listner configured

    As indicated below in you config file it should have

    <log4net>
        <appender name="TraceAppender1" type="log4net.Appender.TraceAppender">
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d [%t],[%c],[%p], %m%n" />
          </layout>
        </appender>
        <root>
          <level value="DEBUG" />
          <appender-ref ref="TraceAppender1" />
        </root>
      </log4net>

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

  • Thursday, February 23, 2012 6:36 PM
     
     

    Hi Sachin,

    Thanks for your reply,

    We are in the process of moving our web application to Cloud, and totally depended on log4net for logging at the application level.  We are trying with the prototype applications how to configure the log4net in our applicaiton after moving to windows azure , with minimal changes to our exisiting code.

    Could you please post completed end to end application, some sort of code how to configure in the exisiting web applcation, it will be great help for us.

    I will try it from my side and contact you for any issues.

    Thanks.

  • Thursday, February 23, 2012 6:50 PM
     
     

    I will have to develop a sample, but it should be simple.

    1. Assuming you have a web applicaiton which is logging using log4net

    2. Add a cloud project and add your web application as web role in the cloud project

    3. In the web.config file add the configuraiton which i shared earlier your log4net and the azure diagnostics configuraiton

    4. You should see logs in WADLogsTable in your storage

  • Thursday, February 23, 2012 7:09 PM
     
     

    Hi Sachin,

    Thanks for you quick response.

    It would be greate if you could provide us with sample.

    I still have some questions, usually if we use log4net we will configure to spool the files up to some gb to trace the logs say we can set the configuration in log4net to create a file after 10 gb of data.

    My question are:

    1.can we transfer the file to blob storage after creating that file (OR) Shall we need to configure the settings to write to a azure table with the message using log4net.

    2.Is there any inbuilt UI interface is available in azure portal to study the logs after saving to the azure tables, with out writing custom code to analyze the logs.

    Thanks.

  • Thursday, February 23, 2012 9:03 PM
     
     Proposed

    Sorry the sample would take some time to answer your questions.

    You can configure the Log4Net to write into the file only thing you have to remember is the folder path for logging file should be passed through LocalResource in the code.

    Check few samples here

    http://cloudshaper.wordpress.com/2010/10/30/logging-with-log4net-on-the-azure-platform/

    http://www.kongsli.net/nblog/2011/08/03/using-log4net-in-azure-compute/

    We can transfer these log files to blob not manually the Azure Diagnostics monitor would do that for us we just need to configure it in our diagnostics configuration in onstart method of the role. Check this please

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

    There is no inbuilt UI but you can use some tools like

    online : https://www.myazurestorage.com/

    Client Tool : http://azurestorageexplorer.codeplex.com/

    Hope this helps.

    • Proposed As Answer by Sachin Sancheti Monday, February 27, 2012 11:05 PM
    •  
  • Wednesday, March 07, 2012 12:55 PM
     
     

    Hi

    Today i was able to successfully host my application in to windows azure cloud.  I have used the log4Net to store the logs in to Azure Table directly as suggested by the the following link.

    http://www.kongsli.net/nblog/2011/08/15/log4net-writing-log-entries-to-azure-table-storage/

    My application was able to log in to the table for some time around 15 entries get logged in to the table, after some time the logging did not happened, I am in confusion where is the problem and how  to check the problem.  Any thoughts by some one here can help me,  Please let me know.

    Thanks.