Log4Net C # - does not write to the database

0

I'm using log4Net as the Log framework for a WinForms APP.

public class Logger
{
private ILog _logErro;
private const string LogErro = "LoggerErro";

public Logger()
{
    Configure();
}

private void Configure()
{
    _logErro = LogManager.GetLogger(LogErro);
}

public void Erro(string mensagem)
{
    _logErro.Error(mensagem);
}

}

In assemblyinfo.cs I have added

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

The log4net.config file has the following contents:

<?xml version="1.0" encoding="utf-8" ?>  
<log4net>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=(localdb)\ProjectsV13;Initial Catalog=XXXXX;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />

<parameter>
  <parameterName value="@log_date" />
  <dbType value="DateTime" />
  <layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>

<parameter>
  <parameterName value="@thread" />
  <dbType value="String" />
  <size value="255" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%thread" />
  </layout>
</parameter>

<parameter>
  <parameterName value="@log_level" />
  <dbType value="String" />
  <size value="50" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%level" />
  </layout>
</parameter>

<parameter>
  <parameterName value="@logger" />
  <dbType value="String" />
  <size value="255" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%logger" />
  </layout>
</parameter>

<parameter>
  <parameterName value="@message" />
  <dbType value="String" />
  <size value="4000" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%message" />
  </layout>
</parameter>

<parameter>
  <parameterName value="@exception" />
  <dbType value="String" />
  <size value="2000" />
  <layout type="log4net.Layout.ExceptionLayout" />
</parameter>

</appender>
<root>
<level value="All" />
<appender-ref ref="AdoNetAppender" />   
</root>
</log4net>

When I run the command:

Logger.Erro("Mensagem de erro");

No error message appears, but it also does not write to the database.

    
asked by anonymous 28.07.2016 / 15:07

0 answers