Recently, we have moved our solution (ASP.NET MVC4) to Windows Azure and are still working well. Our only problem is that we cannot find the log files no matter what method we implement:
In fact, our existing application uses the log4net structure for logging purposes. Once we have moved our solution to Windows Azure, we still want to use log4net in azure with minimal changes to our existing code. We have completed many blogs and tutorials to implement the following methods:
- Synchronize the log file with the memory block using the Windows Azure Diagnostic Module.
- Using a custom log4net application to write directly to table storage.
- Logging to the trace log and synchronizing with table storage.
Unfortunately, none of the above brought the desired result. We are still not able to access our magazines. Is there an official source on how to use Log4net with Windows Azure?
Step 1: I imported Log4net.Azure as a link to my MVC4 WebRole application
Step 2: I added the configuration lines to the On_Start method of the WebRole class
public class WebRole : RoleEntryPoint { private static readonly ILog _logger = LogManager.GetLogger(typeof(WebRole)); public override void Run() { _logger.InfoFormat("{0} entry point called", typeof(WebRole).Name); while (true) { Thread.Sleep(10000); _logger.Debug("Working..."); } } public override bool OnStart() { BasicConfigurator.Configure(AzureAppender.New(conf => { conf.Level = "Debug"; conf.ConfigureRepository((repo, mapper) => { repo.Threshold = mapper("Debug");
Step 3: I create an instance of ILog when I need to write a log, here is an example:
public class TestController : ApiController { private static readonly ILog _logger = LogManager.GetLogger(typeof(WebRole)); [HttpGet] public String Get() { _logger.InfoFormat("{0} entry point called", typeof(WebRole).Name); _logger.Debug("<<<<<<<<<< WS just invoked >>>>>>>>>>>>..."); return "hello world logs on Azure :)"; } }
source share