首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用NLOG记录当前可用内存

如何使用NLOG记录当前可用内存
EN

Stack Overflow用户
提问于 2017-07-28 00:46:01
回答 1查看 992关注 0票数 3

我试图找出我的应用程序中只在生产环境中才会发生的内存泄漏,因为这样的检测会削弱性能,所以我考虑使用NLOG并在日志中输出进程的processinfo:PrivateBytes64/PagedSystemMemorySize64,试图找到内存意外增长的确切位置。问题是,由于这是一个IIS进程,尽管IIS报告私有字节一直在快速增加,但它几乎是不变的。因此,我现在尝试输出系统内存使用情况,而不是进程信息本身。我已经分析了所有可用的布局渲染,但没有找到(或错过了)系统信息!

我真的错过了吗?以下是可用的布局渲染器:

代码语言:javascript
复制
${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的垃圾收集器属性,它可以像下面这样的${gc} (或%{gc:property=TotalMemory})在NLOG中使用。我正在使用它,看到内存消耗急剧增加,但最初的问题仍然存在。

EN

回答 1

Stack Overflow用户

发布于 2020-04-04 19:41:57

你已经在对你的问题的评论中提到了答案:

代码语言:javascript
复制
${gc:property=TotalMemory}

另请参阅:https://github.com/NLog/NLog/wiki/Gc-layout-renderer

PerformanceCounter-Layout- NLog 4.6改进了性能计数器-布局-渲染器,因此它可以自动找到当前的流程-实例(如果没有指定实例属性)。当使用"Process"-category中的计数器时。

另请参阅:https://github.com/nlog/nlog/wiki/PerformanceCounter-Layout-Renderer

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45356621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档