3
votes

Early in a web app project, I decided to use Nlog as my logging solution and really like the idea of just making calls to a logger class in my code and then decide at run-time what and where to log. Then we decided that this app should be hosted in Windows Azure in a Web Role, to take advantage of all that offers. Now, I realize that Nlog isn't going to work the way I had envisioned it. Here are the issues raised by the change:

  • It can't log to a text file in a standard log folder, because the folders are read-only, and even if they weren't, they'd be instance dependent and not persistent because of the way instances and instance local storage is provisioned and will disappear on recycle.
  • Because these config files are read-only, I can't take advantage of the most powerful feature of Nlog, that being the ability to decide at run-time how to configure the output.

I have found some solutions to the issue of where to log. Either configuring a target to log to the Azure Diagnostics table or to the role's table storage. While this may be the way we have to do it, it seems very limiting, because it would seem that you can only log to a single table (diagnostics or custom table for the role). Is anyone aware of a better solution? Logging to an AzureSQL database would be too expensive.

Also, how could I configure Nlog, if I wanted to temporarily log to a database or SMS, email, etc., if I can't edit the config file. I know you can store info in the ServiceConfiguration.cscfg file and it is accessible and editable at runtime, but AFAIK, that's not an option for Nlog configurations. Is there a way to edit a deployed web.cfg or Nlog config file for all instances?

Because of these limitations, would it be best to scrap using Nlog, and go with a different, more compatible logging method?

2

2 Answers

2
votes

Richard,

For the first problem, you can set up a local storage resource to store log files. You can configure local resource to not clear on role restart, which helps your logs live long enough to be useful.

I don't think storing the logging configuration in the .cscfg file is a good way to go, unless you have a management solution that allows you to update all configurations at once. A better approach is to have the configuration file in blob storage, then have a process check if the blob has changed. If it has, download the file and use it.

Erick

1
votes

I know this is a bit of old question, but I'll drop my two cents.

We are using logentries.com service to keep our logs. Free tier keeps your data for a week, which is long enough for us. We do keep configuration of logger in separate log file, but we never had to change the logger config files when deployed.

And just today I've stumbled on project that allow you to store nlog config file in .cscfg. I have not tried this myself yet, but I'll give it a go for my new project. Here is the link: NLog.Config.Azure