NLog MessageBox target not found

1

I am unable to use the NLog MessageBox target in a WinForm application. The config file indicates the xsi:type is invalid. When I run the program I get this error:

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'

My config file contains this:

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

If I change the target to "Console" everything works. Why does MessageBox not work?

NLog 4.5.11, NLog.Schema 4.5.11, .NET Framwork 4.7.2, VS 2017 Pro (15.9.7)

nlog
asked on Stack Overflow Feb 26, 2019 by Bob V • edited Feb 27, 2019 by Julian

1 Answer

1

For the MessageBox target you need to install the NLog.Windows.Forms NuGet package.

See also: https://nlog-project.org/config/?tab=targets&search=messagebox

enter image description here

answered on Stack Overflow Feb 27, 2019 by Julian • edited Feb 27, 2019 by Julian

User contributions licensed under CC BY-SA 3.0