NLog xsi:type not working with custom target

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

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'

回答1:

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".



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!