0

I followed this tutorial and was able to get both of the projects working with my instance of sql server 2012:

However, when I included HLogger project within my solution (instead of using it together with the sample project above), it did work.

The following is a code snippet that worked for me when running it from the provided sample project; however, when I added this library to my own solution, it did not work.

    ILog log = log4net.LogManager.GetLogger("NHibernateLogging");
    log.Error("Error!", new Exception("Exception123"));
    log.Warn("Warning");    

Nothing happened. Nothing was thrown. The database was not populated. I am using the same hibernate.cfg.xml file as the one provided (and worked in conjuncture with the "sample project"):

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">
      NHibernate.Connection.DriverConnectionProvider
    </property>
    <property name="connection.driver_class">
      NHibernate.Driver.SqlClientDriver
    </property>
    <property name="connection.connection_string">
      Server=------.net;database=mydb;user id=myuser;password=sdofjosidfjoijsf;persist security info=true;
    </property>
    <property name="dialect">
      NHibernate.Dialect.MsSql2000Dialect
    </property>
    <property name="show_sql">
      true
    </property>
    <property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
  </session-factory>
</hibernate-configuration>

The only change was to the app.config file. It used to be:

<section name="log4net"
  type="log4net.Config.Log4NetConfigurationSectionHandler,log4net-net-1.0" />

and now it is:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

The reason for this is that I cannot have multiple versions of log4net in the same solution, and I do not have a choice on my current log4net version due to its capabilities with being able to log the version 2 of masstransit with msmq.

The projects in the codeproject site were created for .NET 3.5, whereas my solution is .net 4.5.

How do I diagnose the reason for not being able to log anything with log4net in a database?

stuartd
  • 70,509
  • 14
  • 132
  • 163
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
  • You need to enable [log4net's internal debugging](http://stackoverflow.com/questions/756125/how-to-track-down-log4net-problems) – stuartd Jan 15 '16 at 10:29

1 Answers1

1

You could start with,

  1. See if the issue is with Log4Net, try adding a FileAppender for the same configuration and see if works

  2. If log4net works then next one is to check the Appender configuration, specially Double check namesapaces of classes / assembly names

Low Flying Pelican
  • 5,974
  • 1
  • 32
  • 43