Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First call of logger.Info extremely slow #25

Open
moabtools opened this issue Mar 6, 2019 · 2 comments
Open

First call of logger.Info extremely slow #25

moabtools opened this issue Mar 6, 2019 · 2 comments

Comments

@moabtools
Copy link

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.

@snakefoot
Copy link
Contributor

snakefoot commented Jun 28, 2020

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

@snakefoot
Copy link
Contributor

There is now an updated nuget-package, that should improve the speed:

https://www.nuget.org/packages/NLog.Mongo/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants