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'
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With