How to track down log4net problems

后端 未结 6 1972
生来不讨喜
生来不讨喜 2020-11-22 05:19

I use log4net all the time, but one thing I\'ve never figured out is how to tell what\'s going on on the inside. For example, I\'ve got a console appender and a database app

6条回答
  •  甜味超标
    2020-11-22 05:49

    Make sure the root application where your entry point is logs something to log4net. Give it one of these:

    private static ILog logger = LogManager.GetLogger(typeof(Program));
    static void Main(string[] args)
    {
        logger.InfoFormat("{0} v.{1} started.", Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Version.ToString());
    

    With 2.0.8, I had an interesting situation. I created a library project and a test exe project that would demo it's capabilities. The library project was set up to use Log4net as was the exe project. The exe project used the assemblyinfo attribute to register the config, yet I was getting no logging output to either the console or the log file. When I turned on log4net internal debug logging, I got some internal messages written to the console, but still none of my normal logs. No errors were being reported. It all started working when I added the above code to my program. Log4net was otherwise setup correctly.

提交回复
热议问题