未找到 NLog MessageBox 目标

NLog MessageBox target not found

我无法在 WinForm 应用程序中使用 NLog MessageBox 目标。配置文件指示 xsi:type 无效。当我 运行 程序时,我得到这个错误:

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'Catalog.Form2' threw an exception. Source=Catalog StackTrace: at Catalog.Form2..ctor() in L:\SourceCode\Catalog\Catalog\Form2.cs:line 29 at Catalog.Program.Main() in L:\SourceCode\Catalog\Catalog\Program.cs:line 16

Inner Exception 1: NLogConfigurationException: Exception when parsing L:\SourceCode\Catalog\Catalog\bin\Debug\NLog.config. Inner Exception 2: ArgumentException: Target cannot be found: 'MessageBox'

我的配置文件包含这个:

<targets>
  <target name="errors" xsi:type="MessageBox" layout="${message}" />
</targets>
<rules>
  <logger name="*" minlevel="Debug" writeTo="errors" />
</rules>

如果我将目标更改为 "Console",一切正常。为什么 MessageBox 不起作用?

NLog 4.5.11, NLog.Schema 4.5.11, .NET 框架 4.7.2, VS 2017 专业版 (15.9.7)

对于 MessageBox 目标,您需要安装 NLog.Windows.Forms NuGet package

另请参阅:https://nlog-project.org/config/?tab=targets&search=messagebox