Why doesn't this code write log output to my Tridion content delivery server?

I have content for managing user content from a user (non-Tridion) database. The connection string for this custom database is incorrect, so I get a 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 is a stack of logs in C: \ Tridion \ log, but the last one changed was changed 20 minutes ago and does not contain the text of my log message (I just searched the database in notepad).

Why is my journal not sent to the journal?

+4
source share
1 answer

You have 2 options:

  • You define the root registry as "DEBUG", but this has the disadvantage of allowing you to use a huge number of journals from all the third-party libraries that Tridion uses. Here is a snippet: <root level="DEBUG"> <appender-ref ref="rollingCoreLog"/> </root>

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

Please note that in the second case, your registrar must be bound to the namespace in Tridion.ContentDelivery. Here is an example:

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

Hope this helps.

PS: answer your question: because you do not have an application for it, and the root log is set to WARN. By default, logback.xml contains appenders only for "com.tridion", but I think the output of this.getType().ToString() does not start from this line.

+3
source

All Articles