Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog with VS 2008 Unit Test

I am trying log some entries in a log file (Log.Trace / Log.Debug) while my VS unit test runs. I have also copied the file NLog.config to out directory through DeploymentItem attribute over class. Still my log file is not created. Any help as to how can we log entries in a file same as we do for normal web application.

like image 859
Ashish Avatar asked Nov 04 '09 10:11

Ashish


1 Answers

I've just found a solution to this problem: Add the App.config file to 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 may put any configuration you wish as with NLog.config file.

like image 174
Alexey Sharayev Avatar answered Nov 06 '22 10:11

Alexey Sharayev