Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-693

Using log4net via nuget is not creating a log file in .NET 5

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Blocker
    • Resolution: Unresolved
    • None
    • None
    • None
    • using visual studio 2022/2019
    • Important

    Description

      Hi,

       

      #Try1

       

      I’m using log4net version 2.0.15 in a .net framework 4.5 class library.

      There I export a Logger that uses log4net.

      using log4net;
      using log4net.Config;
      using System.IO;namespace Logger
      {
          public class MyLogger
          {
              private static readonly ILog log = LogManager.GetLogger(typeof(MyLogger));        public MyLogger()
              {
                  // Set up log4net
                  var logRepository = LogManager.GetRepository(System.Reflection.Assembly.GetExecutingAssembly());
                  XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
              }        public void Log(string message)
              {
                  log.Info(message);
              }
          }
      }
       

      In addition I have a console app that uses the Logger.

      using System;namespace Client
      {
          class Program
          {
              static void Main(string[] args)
              {
                  var logger = new Logger.MyLogger();
                  logger.Log("Start");            Console.WriteLine("Press any key to exit.");
                  Console.ReadKey();
              }
          }
      }
       

      Excepted result:

      Create a log file with the Start word written in.

       

      Actual result:

      The log file is not created.

       

      #Try 2

       

      Instead of using nuget package, I cloned the log4net source code and added a reference to the log4net project.

      This way it worked fine.

       

      I’m not sure what the issue is..

      Any help is highly appreciated!

       

      Thx,

      Rachel

      Attachments

        Activity

          People

            Unassigned Unassigned
            rachel23 rachel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: