NLog与VS 2008单元测试 [英] NLog with VS 2008 Unit Test

查看:209
本文介绍了NLog与VS 2008单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在运行VS单元测试时记录日志文件(Log.Trace / Log.Debug)中的一些条目。我也通过类的DeploymentItem属性将文件NLog.config复制到了目录。我的日志文件还没有创建。任何帮助,我们如何登录一个文件中的条目,就像我们正常的Web应用程序一样。

找到了这个问题的解决方案:
将App.config文件添加到您的单元测试项目中,其中包含以下内容:

 <?xml version =1.0encoding =utf-8?> 
<配置>
< configSections>
< section name =nlogtype =NLog.Config.ConfigSectionHandler,NLog/>
< / configSections>

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

<目标>
< target name =debugLogxsi:type =Console/>
< / targets>

< rules>
< / rules>

< / nlog>

< / configuration>

您可以像NLog.config文件一样放置任何您想要的配置。 b

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.

解决方案

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.

这篇关于NLog与VS 2008单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆