我试图找出我的应用程序中的内存泄漏,这只发生在生产中,因为这样的工具会削弱性能,所以我考虑使用NLOG并输出过程' processinfo:日志中的PrivateBytes64 / PagedSystemMemorySize64,试图找到内存意外增长的确切位置。问题是,由于这是一个IIS进程,私有字节几乎是不变的,尽管IIS报告它正在快速增长。所以我现在尝试输出系统内存使用情况而不是过程信息本身。我已经分析了所有可用的布局渲染,但没有找到一个(或错过了一个)系统信息!
我真的错过了吗?以下是可用的布局渲染器:
${activityid} - Puts into log a System.Diagnostics trace correlation id.
${all-event-properties} - Log all event context data.
${appdomain} - Current app domain.
${assembly-version} - The version of the executable in the default application domain.
${basedir} - The current application domain's base directory.
${callsite} - The call site (class name, method name and source information).
${callsite-linenumber} - The call site source line number.
${counter} - A counter value (increases on each layout rendering).
${date} - Current date and time.
${document-uri} - URI of the HTML page which hosts the current Silverlight application.
${environment} - The environment variable.
${event-properties} - Log event properties data - rename of ${event-context}.
${exception} - Exception information provided through a call to one of the Logger.*Exception() methods.
${file-contents} - Renders contents of the specified file.
${gc} - The information about the garbage collector.
${gdc} - Global Diagnostic Context item. Dictionary structure to hold per-application-instance values.
${guid} - Globally-unique identifier (GUID).
${identity} - Thread identity information (name and authentication information).
${install-context} - Installation parameter (passed to InstallNLogConfig).
${level} - The log level.
${literal} - A string literal.
${log4jxmlevent} - XML event description compatible with log4j, Chainsaw and NLogViewer.
${logger} - The logger name.
${longdate} - The date and time in a long, sortable format yyyy-MM-dd HH:mm:ss.ffff.
${machinename} - The machine name that the process is running on.
${mdc} - Mapped Diagnostics Context - a thread-local structure.
${mdlc} - Async Mapped Diagnostics Context - a thread-local structure.
${message} - The formatted log message.
${ndc} - Nested Diagnostics Context - a thread-local structure.
${ndlc} - Async Nested Diagnostics Context - a thread-local structure.
${newline} - A newline literal.
${nlogdir} - The directory where NLog.dll is located.
${performancecounter} - The performance counter.
${processid} - The identifier of the current process.
${processinfo} - The information about the running process.
${processname} - The name of the current process.
${processtime} - The process time in format HH:mm:ss.mmm.
${qpc} - High precision timer, based on the value returned from QueryPerformanceCounter() optionally converted to seconds.
${registry} - A value from the Registry.
${shortdate} - The short date in a sortable format yyyy-MM-dd.
${sl-appinfo} - Information about Silverlight application.
${specialfolder} - System special folder path (includes My Documents, My Music, Program Files, Desktop, and more).
${stacktrace} - Stack trace renderer.
${tempdir} - A temporary directory.
${threadid} - The identifier of the current thread.
${threadname} - The name of the current thread.
${ticks} - The Ticks value of current date and time.
${time} - The time in a 24-hour, sortable format HH:mm:ss.mmm.
${var} - Render variable (new in 4.1)
${windows-identity} - Thread Windows identity information (username).
https://github.com/nlog/nlog/wiki/Layout-Renderers
经过一番研究,一个好的候选者是名为TotalMemory的垃圾收集器属性,它可以在NLOG中使用,如${gc}
(或%{gc:property=TotalMemory}
)。我使用它并看到内存消耗飙升,但最初的问题仍然存在。
答案 0 :(得分:1)
您在对问题的评论中自己提到了答案:
${gc:property=TotalMemory}
另请参阅:https://github.com/NLog/NLog/wiki/Gc-layout-renderer
NLog 4.6改进了PerformanceCounter-Layout-Renderer,因此它会自动查找当前的流程实例(如果未指定Instance-property)。在“处理”类别中使用计数器时。
另请参阅:https://github.com/nlog/nlog/wiki/PerformanceCounter-Layout-Renderer