Jero
Jero

Reputation: 212

Azure cloud service + log4net. How to change log4net config without redeploy

I have a pretty standard cloud service (1 web role + 1 worker role). I am using log4net as the logging framework and it's working fine. One of the advantages of log4net is that you can change the configuration on the fly. e.g. change the logging level from Info to Debug. But that relies on you updating the logging config file on the server - something you can't do in a cloud service.

Has anyone tackled this? Is there a way, a technique, a best practice for setting up your log4net config in such a way that you can update it on the fly without having to redeploy the whole package?

Upvotes: 0

Views: 498

Answers (2)

Jason Haley
Jason Haley

Reputation: 3800

Quick answer is you can RDP to the instance(s) and change the config files there. Though that is not long term solution for you.

If your instance has to be taken down by azure to do an update on the OS, you will lose those changes in the config due to the instance being restored using the uploaded package you created originally (pre RDP and config modifications). This is one huge scenario that is a lot easier in Web Apps.

For log4net I've seen a couple approaches (though I haven't personally implemented either):

  1. Grab a configuration for the log4net at runtime from blob storage at startup time. This would allow your instances to get the config externally. So you could just put what changes you need in blob storage and restart your service to have it grab the latest.
  2. Use the settings in the cscfg file in your application and build the log4net dynmically at runtime. This would allow you to change the settings in the azure portal that will then push the changes out to your Cloud Service instances.

Both require you to more or less write some code that will dynamically configure log4net at runtime. If you do a search for "Changing log4net config dynamically" you should find something that is close to what you would need to do.

Upvotes: 1

qux
qux

Reputation: 1165

You could use the Cloud Explorer in Visual Studio 2015 to remotely edit the Web.config file of your Web App to change your log4net config.

Be aware that your changes will be overridden the next time you redeploy if you do not also commit your change upstream.

Upvotes: 0

Related Questions