NLog with VS 2008 Unit Test

I am trying to register some entries in a log file (Log.Trace / Log.Debug) while VS unit test is running. I also copied the NLog.config file to the directory through the DeploymentItem attribute above the class. However, my log file is not created. Any help on how we can write records to a file is the same as we do for a regular web application.

+5
source share
2 answers

I just found a solution to this problem: Add the App.config file to the yout unit test project with the following contents:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  </configSections>

  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>
      <target name="debugLog" xsi:type="Console" />
    </targets>

    <rules>
      <logger name="*" minlevel="Debug" writeTo="debugLog"></logger>
    </rules>

  </nlog>

</configuration>

You can put any configuration as you wish, as in the NLog.config file.

+11
source

, XML . , . NLog.config - .

, . , , NLog.config App.config =/

, , nlog , . debug nlog, , .....

, internalLogFile internalLogLevel nlog:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogFile="C:/logs/nlog.txt" internalLogLevel="Debug">

:

    InternalLogger.LogFile = @"c:\logs\nlog.txt";

    InternalLogger.LogLevel = LogLevel.Trace;
0

All Articles