Skip to content
brad-wechter edited this page Sep 24, 2014 · 5 revisions

Better CMS uses NLog for logging purposes. For an example, refer to the following web.config configuration:

<configSections>
  <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" requirePermission="false" />
  <sectionGroup name="common">
    <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" requirePermission="false" />
  </sectionGroup>
  [...]
</configSections>
<common>
  <logging>
    <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
      <arg key="configType" value="FILE" />
      <arg key="configFile" value="~/Config/nlog.config" />
    </factoryAdapter>
  </logging>
</common>

Example ~/Config/nlog.config:

<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <targets>
    <target name="console" xsi:type="Console" layout="${date:format=HH\:MM\:ss} ${logger} ${message}" />
    <target name="sql_to_file" xsi:type="File" fileName="${basedir}/logs/bettercms-sql.log" archiveFileName="${basedir}/logs/sql_log_${shortdate}_{#####}.log" layout="${longdate} ${message}${newline}${exception:format=message,tostring:maxInnerExceptionLevel=10:innerFormat=message,tostring}" concurrentWrites="true" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="100" />
    <target name="log_file" xsi:type="File" fileName="${basedir}/logs/bettercms.log" archiveFileName="${basedir}/logs/error_log_${shortdate}_{#####}.log" layout="${longdate} ${message}${newline}${exception:format=message,tostring:maxInnerExceptionLevel=10:innerFormat=message,tostring}" concurrentWrites="true" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="100" />    
  </targets>
  <rules>
    <logger name="NHibernate.SQL" writeTo="sql_to_file" minlevel="Debug" />    
    <logger name="*" writeTo="log_file" minlevel="Trace" maxlevel="Fatal" />
  </rules>
</nlog>

For additional information on how to configure NLog, please visit http://nlog-project.org/

Note: Logging the Lucene search module is discussed here

Clone this wiki locally