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

NLog causes memory leak #2369

Closed
karlovnv opened this issue Oct 25, 2017 · 10 comments
Closed

NLog causes memory leak #2369

karlovnv opened this issue Oct 25, 2017 · 10 comments
Labels

Comments

@karlovnv
Copy link

Bug

NLog version: 5.0.0-beta05
Platform: .NET Core, aspnet.core (hosted in IIS)

Current NLog config (xml or C#, if relevant)

<?xml version="1.0" encoding="utf-8"?>
<nlog autoReload="true" internalLogLevel="Error" internalLogFile="c:\logs\internal-log.txt" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <variable name="logDirectory" value="c:/logs/xxxx" />
    <extensions>
        <add assembly="NLog.Extended" />
    </extensions>
    <targets >
        <!-- comment out buffering wrapper to solve memory leak issue partialy; 
               also async="true" has been removed -->

        <!--default-wrapper xsi:type="BufferingWrapper" bufferSize="10" FlushTimeout="1000" /-->

        <target name="fileinfo" xsi:type="File" fileName="${logDirectory}\info.log" layout="${newline}${longdate}:
${newline}${message}" archiveFileName="${logDirectory}\info{#####}.log" archiveAboveSize="1024000" archiveNumbering="Sequence" concurrentWrites="true" keepFileOpen="false" />

        <target name="fileexception" xsi:type="File" fileName="${logDirectory}\err.log" layout="${newline}${longdate}:&gt;&gt; 
${newline}MESSAGE 
${newline}${message}
${newline}${exception:format=Message,Type,Method,ToString,StackTrace:maxInnerExceptionLevel=5:innerFormat=ToString}" archiveFileName="${logDirectory}\err{#####}.log" archiveAboveSize="1024000" archiveNumbering="Sequence" concurrentWrites="true" keepFileOpen="false" />
    </targets>

    <rules>
        <logger name="*" level="Fatal" writeTo="fileexception" />

        <logger name="*" level="Error" writeTo="fileexception" />
    </rules>
</nlog>

In case of a BUG:

  • What is the current result?

There are too much internal objects (such as Nlog.Common.LogEventInfoBuffer, Nlog.Layouts.*, Nlog.Internal.LoggingRule, AppDomainWrapper, and so on) in process dump, that leads to memory leak.

When async mode (async="true"), buffering and autoreload features are enabled process grows rapidly (up to 100 mb/min ).

We disabled async mode and buffering wrapper and as a result of the speed of growing was decreased.

Memory dump:
image

The size of all Nlog objects is about 300 MB:
image

  • What is the expected result?
  • Did you checked the Internal log?
    It is empty, but in case of internal log level=warn log is full of messages like 'unused target fileinfo'
  • Please post full exception details (message, stacktrace, inner exceptions)
    No exceptions
  • Are there any work arrounds? yes/no
    no
  • Is there a version in which it did worked?
    version for .net worked fine
  • Can you help us by writing an unit test?

I think that the issue is related to #1846, #2220, #316 and #1846

@snakefoot
Copy link
Contributor

snakefoot commented Oct 25, 2017

@karlovnv I think that the issue is related to #1846, #2220, #2343

Great research on finding similar issues, and I guess you have followed the advice presented in those issues:

And what are your results after following this advice?

@snakefoot
Copy link
Contributor

Also maybe consider removing target name="fileinfo" since no logging-rule is pointing to this target.

@karlovnv
Copy link
Author

Thank you for reply, I'll keep you informed.

@snakefoot
Copy link
Contributor

@karlovnv Have your memory issues been resolved?

@304NotModified
Copy link
Member

Closing this due to inactivity. Please let us know if this still an issue and please provide the requested info.

@karlovnv
Copy link
Author

We downgraded to 4.x and then the issue was resolved

@304NotModified
Copy link
Member

4.5?

@karlovnv
Copy link
Author

Now we use 4.4.12 and 5.0.0-beta11 for full framework and .net core projects correspondingly. It seems that memory leak is disappeared.

Thank you for the instructions!

@saboorahmed
Copy link

I am using NLogv4.9.7 along with NLog.Extension.Loggingv1.7.1 and facing memory leakages.

Config file:
image

Memory Dump using PerfView:

image

@snakefoot
Copy link
Contributor

snakefoot commented Apr 25, 2021

@saboorahmed Please create new issue, instead of awaking old issues (Please also include steps to re-produce the problem. Maybe an issue with continous autoload of NLog LoggingConfiguration? Also there seems to a disconnect between you NLog.config and use of DatabaseParameterInfo and NLogLoggingConfiguration).

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

No branches or pull requests

4 participants