1

I have the following logback.xml configuration

<?xml version="1.0" encoding="UTF-8"?>
<configuration>      
    <appender name = "DB" class="ch.qos.logback.classic.db.DBAppender">
        <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
            <driverClass>com.microsoft.sqlserver.jdbc.SQLServerDriver</driverClass>
            <url>jdbc:sqlserver://servername:1433;databaseName=dbname</url>
            <user>user</user>
            <password>pass</password>
        </connectionSource>
    </appender>                
    <root>
        <level value="debug" />
        <appender-ref ref="DB" />        
    </root>
</configuration>

and was expecting this simple test to create an entry in the logging_event_exception table:

 public static void main(String[] args) {
        Logger logger = LoggerFactory.getLogger(MyClass.class);
        try {
            throw new RuntimeException("some error");
        } catch (RuntimeException e) {
            logger.error("test");
        }


    }

but it only inserts an entry into the logging_event_table. What am I missing in the configuration?

Thanks.

dmz73
  • 1,588
  • 4
  • 20
  • 32
  • Your configuration file seems fine except ` ` **Try this** ` ` – Prakhar Asthana Dec 02 '14 at 10:29
  • That change didn't help, it still doesn't write anything to logging_event_exception. – dmz73 Dec 02 '14 at 12:21
  • 1
    Tell me version of jar you are using for SQL server. DBAppender has been tested only on Microsoft SQL Server 2005 2.0.1008.2 (sqljdbc.jar). Check this out : http://logback.qos.ch/manual/appenders.html – Prakhar Asthana Dec 02 '14 at 12:49
  • I am using sqljdbc4-4-0.jar. – dmz73 Dec 02 '14 at 13:03
  • 1
    Jar version could be an issue. Let me check it once. Till then go through this link also : [link](http://learningviacode.blogspot.in/2014/01/writing-logs-to-database.html) – Prakhar Asthana Dec 02 '14 at 13:10
  • I should call this method `public void error(String msg, Throwable t);` for logback to write to the logging_event_exception. Thanks. – dmz73 Dec 02 '14 at 13:32
  • Can you post the maven dependencies for all logback artifacts and your mssql-server jdbc version? (Maybe in the original question?) . I'm facing the "DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect" issue, even though I was/am using your exact logback.xml xml configuration (in your question). Thanks! – granadaCoder Jan 19 '19 at 14:22
  • Yeah, those maven dependencies would be greatly appreciated. I found this (https://github.com/qos-ch/logback/blob/master/logback-classic/src/test/input/integration/db/sqlserver-with-driver.xml) and its still bugging on me. Thanks for your consideration. – granadaCoder Jan 19 '19 at 14:26
  • Future readers (mssql-server specific) may benefit from my answer here (url) where I list dependency versions. and list an important debugging tip. https://stackoverflow.com/questions/33186668/spring-boot-logback-db-appender-properties/54288986#54288986 – granadaCoder Jan 22 '19 at 07:01

1 Answers1

3

Found the solution as explained in my last own comment: for logback to write to the logging_event_exception table I have to call the public void error(String msg, Throwable t)method.

dmz73
  • 1,588
  • 4
  • 20
  • 32