gpt4 book ai didi

c# - 如何使用 NLOG 记录当前可用内存

转载 作者:行者123 更新时间:2023-12-02 09:22:12 25 4
gpt4 key购买 nike

我试图找出我的应用程序中仅在生产中发生的内存泄漏,因为这样的检测会削弱性能,所以我考虑使用 NLOG 并将进程的 processinfo:PrivateBytes64/PagedSystemMemorySize64 在日志中输出到尝试找到内存意外增长的确切位置。问题是,由于这是一个 IIS 进程,因此私有(private)字节几乎保持不变,尽管 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=总内存})。我正在使用它并看到内存消耗猛增,但最初的问题仍然存在。

最佳答案

您自己在问题评论中提到了答案:

${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

关于c# - 如何使用 NLOG 记录当前可用内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45356621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com