Using log4net in windows azure??
Hi Chandan_panda,
Have a look at
http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/4937172d-866f-48fc-9bdf-05ace25bd87e
I this explain how you can make you own log4net appender and let you hook into the azure diagnostics infrastructure.
Hans
Hi,
In addition to what Hans said here's a nice article that explains how to create a custom log4net appender to log in Windows Azure storage.
hi hans ,
I already went through the links that u have provided they did not helped me much.I am giving the steps that i followed to make a POC on log4net in azure.Please suggest me if there is any other workaround.
1.I have created Webrole project and added log4net reference to it.
2.In the Web.config file I added the following changes
<log4net>
<appender name="Appender" type="DebugAppender,MyAssembly">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger - %message" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="azure" />
</root>
</log4net>
3.And have set the DiagnosticMonitor and log4net in OnStart method of WebRole.cs.
4.My Appender class is as follows:
public class DebugAppender : AppenderSkeleton
{
protected override void Append(LoggingEvent loggingEvent)
{
System.Diagnostics.Debug.WriteLine(loggingEvent.Level.Name, loggingEvent.RenderedMessage);
}
}
but still it does not work.Can u suggest me any specific steps that would help.
links reffered for above POC:http://www.gine.jp/blog/taka/post/Azure-e381a6-log4net-e38292e4bdbfe38186.aspx
and http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/4937172d-866f-48fc-9bdf-05ace25bd87e
Hi,
Does your role deployment fail or does it just not log anything?
You could take a totally different approach by leaving the logging as it was in your on-premises app. You can instructuct DiagnosticMonitor to periodically transfer Directories to blob storage. Neil MacKenzie wrote a nice article about the subject.
HI,
Wat exactly is not working?
Do you have diagnostics to begin with?
How are diagnostics configured, with what level?
Are the statements not showing up in your diagnosticstrace in blob storage?
Could you provide the config voor diagnostics?
Hi Patriek
Its Not logging any thing And can u say me what exactly i have to change in the web.config of a webrole Application.And i am using the local development storage for now.this is my diagnostic on start code:
CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
{
configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
RoleEnvironment.Changed += (sender, arg) =>
{
if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>()
.Any((change) => (change.ConfigurationSettingName == configName)))
{
if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
{
RoleEnvironment.RequestRecycle();
}
}
};
});
// DiagnosticMonitor
DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
DiagnosticMonitor.Start("DiagnosticsConnectionString", dmc);
RoleEnvironment.Changing += RoleEnvironmentChanging;
// log4net
string log4netConfig = RoleEnvironment.GetConfigurationSettingValue("log4netConfig");
log4net.Config.XmlConfigurator.Configure(new System.Uri(log4netConfig));
return base.OnStart();
Hi,
In your web.config set a rollingFile appender to log to a directory on your WebRole instance. You need to configure LocalStorage to use that directory. Neil explains in his post how you can use LocalStorage and the DiagnosticMonitorConfiguration to transfer the logfiles, created by log4net in a standard manner, to Blob Storage.
You have to pay attention though to the fact the Diagnostics has changed since Neil's post, but he has written more posts on how to deal with the changes. The main idea is there.
i have followed these links:
http://www.gine.jp/blog/taka/post/Azure-e381a6-log4net-e38292e4bdbfe38186.aspx
and http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/4937172d-866f-48fc-9bdf-05ace25bd87e for the above POC
what is the link for the rolling Appender?
i have followed these links:
http://www.gine.jp/blog/taka/post/Azure-e381a6-log4net-e38292e4bdbfe38186.aspx
and http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/4937172d-866f-48fc-9bdf-05ace25bd87e for the above POC
chandan123
LOL! If I follow the first link I don't think I'd figure anything out until I've studied Japanese ;-).
Anyway, the link I provided earlier was not about getting the custom log4net appender to work, but more like an alternative to get your problem soved.
Please check to see if you diagnostics are configured correctly, do so by outputting a statement directly to the diagnostics trace
System
.Diagnostics.Trace.TraceInformation("TESTTEST"); see if this shows up.
If diagnostics are up it's likely log4net isn't started in the proper appdomain
From sdk 1.3 there are two appdomains due to the full iis option added see http://azurefeeds.com/post/1622/New_Full_IIS_Capabilities_Differences_from_Hosted_Web_Core_.aspx
so you
// log4net
string log4netConfig = RoleEnvironment.GetConfigurationSettingValue("log4netConfig");
log4net.Config.XmlConfigurator.Configure(new System.Uri(log4netConfig));
Should be in the application start event in the global asax
Hi,
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); }
HI Hans
Now my Diagnostic monitor is working fine but When i am logging using log4net I am getting an error.
"The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
I have made the following change in Web.config for log4net
<config>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</config>
<appSettings></appSettings>
<log4net>
<appender name="azure" type="AzureRoleManagerAppender,MyAssembly">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger - %message" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="azure" />
</root>
</log4net>
Is there any kind of change that is required in the Web.config of the application for log4net?
Hi Chandan,
Thats something I get when I leave my web.config checked in and then its read-only, my service fail to start and its in a faulted state. So make sure your web.config is editable when running on the dev fabric.
Hans
Hi Chandan,
Make the web.config editable when publishing to development fabric. That should resolve the faulted state error.
As for you config, it looks ok to me. If configured it by code see my earlier reply (just for testing purposes).
Hans
Hi Hans,
I have also same problem .Can you please share the code .
It will be very helpful .
Thanks in advance.
Hi Prasanna,
Please describe you exact problem, because I think Chandan could have serveral.
If you have a faulted state during development fabric start, check to see if you web.config is editable in other words it has the Read-only flag turn OFF.
I you still have the same error (faulted state) enable WCF diagnostics and view log files/
As for code see my comment in this thread: Wednesday, February 09, 2011 12:04 PM
Hi Chandan
check the below link(you 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>
Hi
Can any one suggest how we can use the email services when we get the error in the application from in the Azure platform using Log4Net.
Usually we configure the Log4Net with SMTPAppender to listen and set the configuration level to Error in for Log4Net to get the emails , when any unhandled exception occured or for some other reasons.
Can any one have any idea or able to configure like this as given below and getting the emails if any error occured, after hosting the application on Windows Azure.
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="to@to.come"/>
<from value="from@from.com"/>
<subject value="Log Message"/>
<smtpHost value="SMPTAddress"/>
<bufferSize value="1"/>
<lossy value="false"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c [%property{UserId}] %m%n"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR"/>
<levelMax value="ERROR"/>
</filter>
</appender>
<root>
<level value="TRACE"/>
<appender-ref ref="SmtpAppender"/>
</root>
Already i have gone through the below articles , but I am trying to find out is there any alternative available using Log4Net with out implementing the custom solutions to achieve this task.
Thanks in Advance.
Hi,
am also phasing this problem.
Regards,
PCS
|