gpt4 book ai didi

unit-testing - NLog 与 VS 2008 单元测试

转载 作者:行者123 更新时间:2023-12-04 17:05:40 25 4
gpt4 key购买 nike

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

最佳答案

我刚刚找到了解决此问题的方法:
将 App.config 文件添加到您的单元测试项目中,内容如下:

<?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>

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

关于unit-testing - NLog 与 VS 2008 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1672998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com