我有一个非常简单的控制台应用程序。我已经添加了Nlog与控制台目标,但我无法让它在单声道(在Windows和ubuntu上)运行时工作。我已经尝试了文件目标,它的工作原理。 我错过了什么?
代码
class Program
{
private static Logger logger = LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
Type t = Type.GetType("Mono.Runtime");
if (t != null)
Console.WriteLine("You are running with the Mono VM");
else
Console.WriteLine("You are running something else");
Console.WriteLine("Lets go Mono");
logger.Trace("Sample trace message");
logger.Debug("Sample debug message");
logger.Info("Sample informational message");
logger.Warn("Sample warning message");
logger.Error("Sample error message");
logger.Fatal("Sample fatal error message");
}
}
配置
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target name="console" xsi:type="Console"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="console" />
</rules>
</nlog>
Nlog包
<package id="NLog" version="4.3.10" targetFramework="net452" />
答案 0 :(得分:3)
您的代码和配置看起来有效。
使用NLog 4.3.10,which will be fixed in 4.3.11的Mono上的控制台目标存在问题。如果控制台可用,则检测无法正常工作,因为<table>
<tr>
<td>
<img src="http://placehold.it/100x100/ffcc00">
<img src="http://placehold.it/100x100/11cc00">
</td>
</tr>
<tr>
<td>
<img src="http://placehold.it/100x100/ffcc00">
</td>
</tr>
</table>
不在Mono上工作
现在为Mono设置Environment.UserInteractive
,所以:
detectConsoleAvailable="false"