I have a multi-tenant application in ASP.NET MVC 5 that can accept client logins from multiple companies. Currently, I'm using log4net to log to files, but it places all the logs from all the companies in one file. Ideally, I would like to separate out the log files so that the logs for each company resides in its own folder.
I see from this question that I can programmatically create additional appenders, which then can log to different log files. But that would mean that for each instance of a class, I would have to keep calling
ILog log = LogManager.GetLogger("CompanyA");
to get the correct logger, right? Is there a better way to do so? I'm also open to using another logger if need be.
Thanks.
Do you use an Ioc container in your application? I was able to solve a similar problem using AutoFac MultitenantContainer. Steps that you need to follow
your code could look like (extract from Autofac wiki)
If this is the only instance where you need to differentiate the tenants and do not want to Ioc at this point you could create the factory like
now use the factory instead of directly using Logmanager