NLog与VS 2008单元测试

Ash*_*ish 5 unit-testing file nlog

我正在尝试在我的VS单元测试运行时记录日志文件(Log.Trace/Log.Debug)中的一些条目.我还通过类的DeploymentItem属性将文件NLog.config复制到out目录.我的日志文件仍未创建.有关如何在文件中记录条目的任何帮助都与我们对普通Web应用程序相同.

小智 12

我刚刚找到了解决此问题的方法:将App.config文件添加到yout unit test project,其中包含以下内容:

<?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>
Run Code Online (Sandbox Code Playgroud)

您可以使用NLog.config文件进行任何您希望的配置.