Unable to configure log4net for .NET Core 2.1 framework












0















I think I tried all possible combinations of calls to make log4net working woth ASP.NET Core 2.1 but no luck so far. I followed steps described in How to use log4net in Asp.net core 2.0 . I also explored all variants described in ASP.NET Core 2.1 + Log4Net.



No luck so far. The log4net.config is copied to the binary folder. It is used (I noticed it being locked when service is running). I used absolute and relative paths.
Called and not called loggerFactory.AddLog4Net("log4net.config");
I called both:



var log4netConfig = new System.Xml.XmlDocument();
log4netConfig.Load(File.OpenRead(@"log4net.config"));
var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
XmlConfigurator.Configure(repo, log4netConfig["log4net"]);


and



ILoggerRepository repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));


ILog is created in the following way:



private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);


But also I used this approach:



var log2 = LogManager.GetLogger(typeof(Startup));
log2.Info("SOME");


Each time log does not have any Appenders created (list is empty) even though Configure method is called.



Of course no file is created. I noticed that some people reported that it can be added to your Core 2.1 project but I haven't discovered yet the right permutation of calls and actions.



Is there a way to trace what is actually log4net doing to be able to fix the problem? So far in my long experience log4net had been the most difficult component to work with.
Or an exact combination of steps?
I am using log4net 2.0.8 nuget.










share|improve this question

























  • Possible duplicate of stackoverflow.com/questions/756125/….

    – Polyfun
    Nov 21 '18 at 12:54











  • Not realy. The example there refers to a project which uses config in XML format. This is ASP.Net Core 2.1 which uses JSON to configure the web application. I don't how to translate that config file into a corresponding json. I am afraid that log4net won't be even looking into it as it cannot use JSON for configuration.

    – Radek Strugalski
    Nov 21 '18 at 14:44











  • Some of the posts in the thread I linked describe how to debug log4net without using a config file.

    – Polyfun
    Nov 21 '18 at 14:59
















0















I think I tried all possible combinations of calls to make log4net working woth ASP.NET Core 2.1 but no luck so far. I followed steps described in How to use log4net in Asp.net core 2.0 . I also explored all variants described in ASP.NET Core 2.1 + Log4Net.



No luck so far. The log4net.config is copied to the binary folder. It is used (I noticed it being locked when service is running). I used absolute and relative paths.
Called and not called loggerFactory.AddLog4Net("log4net.config");
I called both:



var log4netConfig = new System.Xml.XmlDocument();
log4netConfig.Load(File.OpenRead(@"log4net.config"));
var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
XmlConfigurator.Configure(repo, log4netConfig["log4net"]);


and



ILoggerRepository repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));


ILog is created in the following way:



private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);


But also I used this approach:



var log2 = LogManager.GetLogger(typeof(Startup));
log2.Info("SOME");


Each time log does not have any Appenders created (list is empty) even though Configure method is called.



Of course no file is created. I noticed that some people reported that it can be added to your Core 2.1 project but I haven't discovered yet the right permutation of calls and actions.



Is there a way to trace what is actually log4net doing to be able to fix the problem? So far in my long experience log4net had been the most difficult component to work with.
Or an exact combination of steps?
I am using log4net 2.0.8 nuget.










share|improve this question

























  • Possible duplicate of stackoverflow.com/questions/756125/….

    – Polyfun
    Nov 21 '18 at 12:54











  • Not realy. The example there refers to a project which uses config in XML format. This is ASP.Net Core 2.1 which uses JSON to configure the web application. I don't how to translate that config file into a corresponding json. I am afraid that log4net won't be even looking into it as it cannot use JSON for configuration.

    – Radek Strugalski
    Nov 21 '18 at 14:44











  • Some of the posts in the thread I linked describe how to debug log4net without using a config file.

    – Polyfun
    Nov 21 '18 at 14:59














0












0








0








I think I tried all possible combinations of calls to make log4net working woth ASP.NET Core 2.1 but no luck so far. I followed steps described in How to use log4net in Asp.net core 2.0 . I also explored all variants described in ASP.NET Core 2.1 + Log4Net.



No luck so far. The log4net.config is copied to the binary folder. It is used (I noticed it being locked when service is running). I used absolute and relative paths.
Called and not called loggerFactory.AddLog4Net("log4net.config");
I called both:



var log4netConfig = new System.Xml.XmlDocument();
log4netConfig.Load(File.OpenRead(@"log4net.config"));
var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
XmlConfigurator.Configure(repo, log4netConfig["log4net"]);


and



ILoggerRepository repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));


ILog is created in the following way:



private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);


But also I used this approach:



var log2 = LogManager.GetLogger(typeof(Startup));
log2.Info("SOME");


Each time log does not have any Appenders created (list is empty) even though Configure method is called.



Of course no file is created. I noticed that some people reported that it can be added to your Core 2.1 project but I haven't discovered yet the right permutation of calls and actions.



Is there a way to trace what is actually log4net doing to be able to fix the problem? So far in my long experience log4net had been the most difficult component to work with.
Or an exact combination of steps?
I am using log4net 2.0.8 nuget.










share|improve this question
















I think I tried all possible combinations of calls to make log4net working woth ASP.NET Core 2.1 but no luck so far. I followed steps described in How to use log4net in Asp.net core 2.0 . I also explored all variants described in ASP.NET Core 2.1 + Log4Net.



No luck so far. The log4net.config is copied to the binary folder. It is used (I noticed it being locked when service is running). I used absolute and relative paths.
Called and not called loggerFactory.AddLog4Net("log4net.config");
I called both:



var log4netConfig = new System.Xml.XmlDocument();
log4netConfig.Load(File.OpenRead(@"log4net.config"));
var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
XmlConfigurator.Configure(repo, log4netConfig["log4net"]);


and



ILoggerRepository repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));


ILog is created in the following way:



private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);


But also I used this approach:



var log2 = LogManager.GetLogger(typeof(Startup));
log2.Info("SOME");


Each time log does not have any Appenders created (list is empty) even though Configure method is called.



Of course no file is created. I noticed that some people reported that it can be added to your Core 2.1 project but I haven't discovered yet the right permutation of calls and actions.



Is there a way to trace what is actually log4net doing to be able to fix the problem? So far in my long experience log4net had been the most difficult component to work with.
Or an exact combination of steps?
I am using log4net 2.0.8 nuget.







c# asp.net-core .net-core log4net asp.net-core-2.1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 14:46







Radek Strugalski

















asked Nov 21 '18 at 12:44









Radek StrugalskiRadek Strugalski

1229




1229













  • Possible duplicate of stackoverflow.com/questions/756125/….

    – Polyfun
    Nov 21 '18 at 12:54











  • Not realy. The example there refers to a project which uses config in XML format. This is ASP.Net Core 2.1 which uses JSON to configure the web application. I don't how to translate that config file into a corresponding json. I am afraid that log4net won't be even looking into it as it cannot use JSON for configuration.

    – Radek Strugalski
    Nov 21 '18 at 14:44











  • Some of the posts in the thread I linked describe how to debug log4net without using a config file.

    – Polyfun
    Nov 21 '18 at 14:59



















  • Possible duplicate of stackoverflow.com/questions/756125/….

    – Polyfun
    Nov 21 '18 at 12:54











  • Not realy. The example there refers to a project which uses config in XML format. This is ASP.Net Core 2.1 which uses JSON to configure the web application. I don't how to translate that config file into a corresponding json. I am afraid that log4net won't be even looking into it as it cannot use JSON for configuration.

    – Radek Strugalski
    Nov 21 '18 at 14:44











  • Some of the posts in the thread I linked describe how to debug log4net without using a config file.

    – Polyfun
    Nov 21 '18 at 14:59

















Possible duplicate of stackoverflow.com/questions/756125/….

– Polyfun
Nov 21 '18 at 12:54





Possible duplicate of stackoverflow.com/questions/756125/….

– Polyfun
Nov 21 '18 at 12:54













Not realy. The example there refers to a project which uses config in XML format. This is ASP.Net Core 2.1 which uses JSON to configure the web application. I don't how to translate that config file into a corresponding json. I am afraid that log4net won't be even looking into it as it cannot use JSON for configuration.

– Radek Strugalski
Nov 21 '18 at 14:44





Not realy. The example there refers to a project which uses config in XML format. This is ASP.Net Core 2.1 which uses JSON to configure the web application. I don't how to translate that config file into a corresponding json. I am afraid that log4net won't be even looking into it as it cannot use JSON for configuration.

– Radek Strugalski
Nov 21 '18 at 14:44













Some of the posts in the thread I linked describe how to debug log4net without using a config file.

– Polyfun
Nov 21 '18 at 14:59





Some of the posts in the thread I linked describe how to debug log4net without using a config file.

– Polyfun
Nov 21 '18 at 14:59












1 Answer
1






active

oldest

votes


















0














Look's like there were 2 issues that added up to manifest the issus as I described above. Actually the log WAS created when at least following the explanation from the first link I provided. But, it was created in the wrong directory.
The bug is explained here (.NET Core console app default working directory is the source directory, not the bin directory): https://github.com/dotnet/project-system/issues/589



Second issue was due to the fact that Logger has empty list of Appenders even though the appenders are loaded and used. This is apparently misleading but I didn't find any explanation to this behaviour. Seems like this is "by design".



So by default .NET Core Console Appliaction working directory is project root directory (sic!) no the bin directory as for .NET Framework case.



And secondly, there are no Appenders in the Logger, but this is not an indication of any problem.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412313%2funable-to-configure-log4net-for-net-core-2-1-framework%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Look's like there were 2 issues that added up to manifest the issus as I described above. Actually the log WAS created when at least following the explanation from the first link I provided. But, it was created in the wrong directory.
    The bug is explained here (.NET Core console app default working directory is the source directory, not the bin directory): https://github.com/dotnet/project-system/issues/589



    Second issue was due to the fact that Logger has empty list of Appenders even though the appenders are loaded and used. This is apparently misleading but I didn't find any explanation to this behaviour. Seems like this is "by design".



    So by default .NET Core Console Appliaction working directory is project root directory (sic!) no the bin directory as for .NET Framework case.



    And secondly, there are no Appenders in the Logger, but this is not an indication of any problem.






    share|improve this answer




























      0














      Look's like there were 2 issues that added up to manifest the issus as I described above. Actually the log WAS created when at least following the explanation from the first link I provided. But, it was created in the wrong directory.
      The bug is explained here (.NET Core console app default working directory is the source directory, not the bin directory): https://github.com/dotnet/project-system/issues/589



      Second issue was due to the fact that Logger has empty list of Appenders even though the appenders are loaded and used. This is apparently misleading but I didn't find any explanation to this behaviour. Seems like this is "by design".



      So by default .NET Core Console Appliaction working directory is project root directory (sic!) no the bin directory as for .NET Framework case.



      And secondly, there are no Appenders in the Logger, but this is not an indication of any problem.






      share|improve this answer


























        0












        0








        0







        Look's like there were 2 issues that added up to manifest the issus as I described above. Actually the log WAS created when at least following the explanation from the first link I provided. But, it was created in the wrong directory.
        The bug is explained here (.NET Core console app default working directory is the source directory, not the bin directory): https://github.com/dotnet/project-system/issues/589



        Second issue was due to the fact that Logger has empty list of Appenders even though the appenders are loaded and used. This is apparently misleading but I didn't find any explanation to this behaviour. Seems like this is "by design".



        So by default .NET Core Console Appliaction working directory is project root directory (sic!) no the bin directory as for .NET Framework case.



        And secondly, there are no Appenders in the Logger, but this is not an indication of any problem.






        share|improve this answer













        Look's like there were 2 issues that added up to manifest the issus as I described above. Actually the log WAS created when at least following the explanation from the first link I provided. But, it was created in the wrong directory.
        The bug is explained here (.NET Core console app default working directory is the source directory, not the bin directory): https://github.com/dotnet/project-system/issues/589



        Second issue was due to the fact that Logger has empty list of Appenders even though the appenders are loaded and used. This is apparently misleading but I didn't find any explanation to this behaviour. Seems like this is "by design".



        So by default .NET Core Console Appliaction working directory is project root directory (sic!) no the bin directory as for .NET Framework case.



        And secondly, there are no Appenders in the Logger, but this is not an indication of any problem.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 17:02









        Radek StrugalskiRadek Strugalski

        1229




        1229
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412313%2funable-to-configure-log4net-for-net-core-2-1-framework%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules