NLog.Mongo
NLog.Mongo copied to clipboard
First call of logger.Info extremely slow
Hi!
I use NLog 4.5.11, NLog.Mongo 4.6.0.68 and MongoDB 4.0.6
My NLog.Config:
<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="d:\temp\nlog-internal.log">
<extensions>
<add assembly="NLog.Mongo"/>
</extensions>
<targets>
<target xsi:type="ColoredConsole" name="logconsole" />
<target xsi:type="Mongo"
name="mongoCustom"
includeDefaults="false"
connectionString="mongodb://localhost:27017/"
collectionName="logs"
databaseName="direct"
cappedCollectionSize="26214400"
cappedCollectionMaxItems="100000">
<field name="Date" layout="${date}" bsonType="DateTime" />
<field name="Level" layout="${level}"/>
<field name="Message" layout="${message}" />
<field name="Logger" layout="${logger}"/>
<field name="Exception" layout="${exception:format=tostring}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logconsole" />
<logger name="*" minlevel="Info" writeTo="mongoCustom" />
</rules>
</nlog>
My code is:
NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
if (args.Length == 0)
{
logger.Info("This process cannot be started by yourself");
return;
}
else
{
logger.Info($"Process Job: TokenId={args[0]}");
}
First call of logger.Info is very slow - 15-20 sec. Next calls are OK.
What I'm doing wrong? Thanks.
Maybe you can try this pre-release-nuget-package (From PR #41) and report the output from NLog InternalLogger (At Debug-Level):
https://ci.appveyor.com/project/LoreSoft/nlog-mongo/builds/33782375/artifacts
There is now an updated nuget-package, that should improve the speed:
https://www.nuget.org/packages/NLog.Mongo/