Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog xsi:type not working with custom target

Tags:

c#

.net

nlog

I wanted to write custom target in NLog using this: https://github.com/nlog/nlog/wiki/How%20to%20write%20a%20Target

and write my logs to MongoDB, so my code looks like this:

namespace NLog.Mongo
{
    [Target("Mongo")]
    public sealed class MongoDBNLogTarget : Target
    {
        ...
        protected override void Write(NLog.LogEventInfo logEvent)
        {
            Repository.Insert(logEvent);
        }
    }
}

and I imagine my NLog.config file should look like this:

<?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">
  <extensions>
    <add assembly="NLog.Mongo"/>
  </extensions>
  <targets>
    <target name="mongo" xsi:type="Mongo"/>
  </targets>

  <rules>
    <logger name="*" minLevel="Info" writeTo="mongo" />
  </rules>
</nlog>

However I get warning:

This is an invalid xsi:type 'http://www.nlog-project.org/schemas/NLog.xsd:Mongo'
like image 423
Miłosz Zięba Avatar asked Nov 21 '14 16:11

Miłosz Zięba


1 Answers

This is a error from the XSD, which should be seen as warning. The XSD is generated with all the possible targets (in the NLog main package) and thus doesn't have the custom targets.

These kind of errors could be ignored and NLog won't stop working if the XML config contains these kind of "errors".

like image 184
Julian Avatar answered Oct 23 '22 04:10

Julian