Skip to content
Jakub Raczek edited this page Apr 25, 2019 · 5 revisions

We are using NLog in our test framework for logging messages during test execution.

Our framework allows to enable EventFiringWebDriver logs. It's disabled by default, to enable it: set in App.config EnableEventFiringWebDriver to "true" and set nlog trace level to "trace" for at least one logger.

<add key="EnableEventFiringWebDriver" value="true"/>

NLog is set in nlog section of App.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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
    <targets>
      <target name="logfile" xsi:type="File" fileName="${basedir}\Test.log" layout="${longdate}|${level}|${callsite}|${message}" />
      <target name="console" xsi:type="ColoredConsole" layout="${longdate}|${level}|${callsite}|${message}"/>
    </targets>
    <rules>
      <logger name="*" minlevel="Trace" writeTo="logfile" />
      <logger name="*" minlevel="Debug" writeTo="console" />
    </rules>
  </nlog>
...
</configuration>

To use NLog in your test project create logger and use it:

private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Logger.Info("Log message");

More info about configuring NLog can be find here.

Clone this wiki locally