C# 你如何写入 NUnit gui runner 的 Log 选项卡和 Console.Error 选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/832506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:25:52  来源:igfitidea点击:

How do you write to the Log tab and Console.Error tab of the NUnit gui runner

c#.netasp.netwinformsnunit

提问by MedicineMan

In the NUnit Gui Runner, there are 6 tabs. I can write to the Console.Out by writing something like:

在 NUnit Gui Runner 中,有 6 个选项卡。我可以通过编写以下内容来写入 Console.Out:

Console.WriteLine("This will end up in the Console.Out");

I can write to the Trace tab by writing something like:

我可以通过编写以下内容来写入跟踪选项卡:

System.Diagnostics.Trace.WriteLine("This will end up on the Trace tab");

But how do I write to the two other tabs, "Log" and "Console.Error"?

但是如何写入另外两个选项卡“Log”和“Console.Error”?

采纳答案by Andy White

To write to Console.Error, you do this:

要写入 Console.Error,请执行以下操作:

Console.Error.WriteLine("blah");

Console.Error.WriteLine("等等");

To write to the Log, you need to configure log4net in your test project, then setup a log4net appender in the .exe.config file for your project. NUnit is actually a little tricky to setup with log4net, here's a little guide to get started:

要写入日志,您需要在测试项目中配置 log4net,然后在项目的 .exe.config 文件中设置 log4net appender。使用 log4net 设置 NUnit 实际上有点棘手,这里有一些入门指南:

http://www.softwarefrontier.com/2007/09/using-log4net-with-nunit.html

http://www.softwarefrontier.com/2007/09/using-log4net-with-nunit.html