Log4net stopped showing logs

Asked

Viewed 135 times

2

My console stopped showing the logs from nowhere, I have compiled several times and never happened this, only now

Code:

    public static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

log.Info("Hello World")

Hello World doesn’t show up, but if I do Console.Writeline("Hello World") appears on the console, what? I wanted the log.Info to appear again.

Could be some bug?

Sometimes only log.error appears.:

inserir a descrição da imagem aqui

  • There must be some configuration missing there in your app, I put detailed in my reply.

1 answer

0


There are 3 items you need to check.

1- App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />  </configSections>
  <log4net>
    <root>
      <level value="ALL" />
      <appender-ref ref="ConsoleAppender" />
    </root>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>

  </log4net>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
</configuration>

2- Assemblyinfo.Cs

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

3- Your Program:

    public static class Program
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        static void Main(string[] args)
        {
            log.Error("Hello World");
            log.Warn("Hello World");
            log.Info("Hello World");
            Console.ReadLine();
        }
    }

Ready :) Exemplo

Source code of my test:

https://github.com/thiagoloureiro/Log4Net

  • I wanted it to be like my Dit, I would have like?

  • 1

    I don’t understand.. what’s wrong with your Edit ? the date? is the format that Voce defines in the log settings.. Here oh <conversionPattern value="%date [%thread] %-5level %logger [%Property{NDC}] - %message%newline" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.