Globally Available Log4Net Variable

I currently have the following setting in application_start

log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config"))); 

now, in order to get to log4net later, I need to add an instance to each controller;

 public static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 

as this is what i want to use throughout the api. Can I declare this in global.asax so that then I can just call:

logger.Error ("Exit");

when it is necessary?

+5
source share

Source: https://habr.com/ru/post/1234603/


All Articles