There are several ways to gather Mail.dll logs. The first step is always the same: logging must be turned on either by using code:
Limilabs.Mail.Log.Enabled = true;
or in configuration file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="Mail.dll" value="Verbose" />
</switches>
</system.diagnostics>
</configuration>
Then you can decide if you want to use:
- standard .NET logging infrastructure (system.diagnostics namespace),
- log4net,
- Log.WriteLine event.
The simplest way is to subscribe to Log.WriteLine event.
Limilabs.Mail.Log.WriteLine += line =>
{
// write line to file,
// or use your logging infrastructure to save line.
Console.WrtieLine(line);
};
You need to subscribe to this event BEFORE the action you want to gather logs for.
Most efficient way to log to file is to use standard .NET logging and log to specific file using app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true"/>
<switches>
<!-- Turns on Mail.dll logging. -->
<add name="Mail.dll" value="Verbose"/>
</switches>
<sources>
<source name="Mail.dll">
<listeners>
<add name="MailLogFile"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add
name="MailLogFile"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\folder-with-write-access\mail.log"/>
</sharedListeners>
</system.diagnostics>
</configuration>
Sample log4net app.config configuration:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
requirePermission="false"/>
</configSections>
<system.diagnostics>
<switches>
<!-- Turns on Mail.dll logging. -->
<add name="Mail.dll" value="Verbose"/>
</switches>
</system.diagnostics>
<log4net>
<appender name="FileAppender"
type="log4net.Appender.RollingFileAppender">
<immediateFlush value="true" />
<file value="log.txt"/>
<appendToFile value="false" />
<maxSizeRollBackups value="5"/>
<rollingStyle value="once"/>
<staticLogFileName value="false"/>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread %date - %message%newline"/>
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
</configuration>
Remember to use:
log4net.Config.XmlConfigurator.Configure();