4
votes

I have a user control rendering content from a custom (non-Tridion) database. The connection string for this custom database is incorrect, and so I'm getting an SqlException when the code tries to connect.

My code is currently:

var logger = 
    Tridion.ContentDelivery.Web.Utilities
        .LoggerFactory.GetLogger(this.GetType().ToString());
try
{
    /* make a database connection - failing with SqlException */ 
}
catch (SqlException e)
{
    logger.Error("Could not connect to database: " + e.ToString());
}

My \bin\config\logback.xml file contains:

<property name="log.pattern" value="%date %-5level %logger{0} - %message%n"/>
<property name="log.history" value="7"/>
<property name="log.folder" value="c:/tridion/log"/>
<property name="log.level" value="DEBUG"/>
...
<appender name="rollingCoreLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${log.folder}/cd_core.%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>${log.history}</maxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>${log.pattern}</pattern>
    </encoder>
    <prudent>true</prudent>
</appender>
...
<root level="warn">
    <appender-ref ref="rollingCoreLog"/>
</root>

There's a stack of logs in C:\Tridion\log, but the most recently changed one was modified 20 minutes ago, and doesn't contain my log message text (I just did a search for "database" in notepad).

Why isn't my log output being sent to the log?

1
Content Delivery server is perfectly correct. I've edited the question to reflect this. - Dominic Cronin

1 Answers

3
votes

You have 2 options:

  • You define the root logging to "DEBUG" but this has the disadvantage that allows a huge amount of logging from all the third-party libraries that Tridion is using. Here is the snippet: <root level="DEBUG"> <appender-ref ref="rollingCoreLog"/> </root>

  • You define a special appender to include also the Tridion .NET logging: <logger name="Tridion.ContentDelivery" level="${log.level}"><appender-ref ref="rollingCoreLog"/></logger>

Note that in the second case you need your logger to be bound to a namespace under Tridion.ContentDelivery. Here is an example:

var logger = Tridion.ContentDelivery.Web.Utilities.LoggerFactory.GetLogger("Tridion.ContentDelivery.MyNamespace.MyClass");

Hope this helps.

P.S.: to answer your question: because you do not have an appender for it and the root logging is set to WARN. By default, the logback.xml contains appenders only for "com.tridion" but I guess that the output of this.getType().ToString() does not start with that string.