I have MyAwesomeProject which imports MyAwesomeLogger and calls it:
using MyAwesomeLogger;
using System.Web.Mvc;
public class HomeController : Controller
{
public ActionResult Index()
{
var Logger = new LogFactory.GetLogger();
Logger.Debug("Hello World");
return View();
}
}
LogFactory.GetLogger()
method is inside MyAwesomeLogger and part of all the wonderful things it does, is sets the file name of the logger. My main problem is that I need to grab the project name and set that as the logging file name and this has to work for both console applications and web applications.
What I tried to do before was: Assembly.GetEntryAssembly().GetName().Name;
While this works for console applications, it does not works for web. I've gone through a lot of links, but most of the solutions show how to get the project name from mvc project itself, not from a dll like this. What is the simplest fool proof way to do this?
Another thing I tried was:
var type = System.Web.HttpContext.Current.ApplicationInstance.GetType();
while (type != null && type.Namespace == "ASP")
{
type = type.BaseType;
}
var fileName = type.Assembly.GetName().Name;
The above works if I call it in the HomeController, but MyAwesomeLogger doesn't know about HttpContext so I can't call it there.