Log4net in Azure
-
venerdì 11 febbraio 2011 11:31
Hi,
I have an existing application which uses log4net framework for Logging purpose.Now i want to use log4net in azure with minimal change in my existing code.
I have gone through various post regarding log4net in azure development forum but it didnt help me .
I have gone through following post :-
1.http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/4937172d-866f-48fc-9bdf-05ace25bd87e
2.http://cloudshaper.wordpress.com/2010/10/30/logging-with-log4net-on-the-azure-platform/#respond
Now what i would like to do is save all the log from log4net to azure table storage(azure storage service) .
In all the post it was mentioned that to set up config file for log4net in SERVICECONFIGURATION.CSFG but when i try to set up configuration in service configuration for log4net ,the project doesn't compile.please help me on this to configure service configuration for log4net .
SO i am stuck up in setting up log4net confing file, and specify the config file in ServiceConfiguration.cscfg and setting up DiagnosticMonitor and log4net in OnStart method of WebRole.cs
Any tutorial for setting up log4net in windows azure will be very helpful.
Any help will be appreciated .
Tutte le risposte
-
venerdì 11 febbraio 2011 12:56
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); }
-
lunedì 14 febbraio 2011 11:46
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>- Modificato Rahul-P lunedì 14 febbraio 2011 11:48 edit
-
giovedì 23 febbraio 2012 09:54
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
-
giovedì 23 febbraio 2012 17:55
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> -
giovedì 23 febbraio 2012 18:36
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.
-
giovedì 23 febbraio 2012 18:50
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
-
giovedì 23 febbraio 2012 19:09
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.
-
giovedì 23 febbraio 2012 21:03
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.
- Proposto come risposta Sachin Sancheti lunedì 27 febbraio 2012 23:05
-
mercoledì 7 marzo 2012 12:55
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.

