4

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?

Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56
George
  • 2,110
  • 5
  • 26
  • 57

1 Answers1

3

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.

Daniel Neagu
  • 1,711
  • 11
  • 13
  • Hi @sea_gull: my root level is currently "warn" and my log is coming out at "error" - shouldn't the root level cover that logging statement? I'm assuming that "warn" covers both "warn" and "error", like it would in log4j. I'm trying to define a new logger with the name "A.B". Assuming that my type is A.B.C.D, my logger.Error() statement should be covered by that logger definition, yes? – George Jan 18 '13 at 00:22
  • Hi @George: you are right, the logging should be in your file. Unless you have some strange definitions which prevent the logging for your specific class. Easiest is indeed to create a logger specially for your class and to take if from there: . – Daniel Neagu Jan 18 '13 at 08:56