简体   繁体   English

实时环境中的System.Diagnostics.Trace

[英]System.Diagnostics.Trace on a live environment

Problems have been reported to me regarding the performance of a live site. 已经向我报告了有关实时站点性能的问题。 I can't seem to replicate any of these issues on any dev or staging environments, and the profilers I have ran against dev has revealed nothing unusual. 我似乎无法在任何开发人员或暂存环境上复制任何这些问题,而且我针对开发人员运行的探查器并未发现任何异常。

This has led me to turn to a diagnostics trace for a simple timing trace so I can at least try and isolate the cause and try and narrow it down. 这导致我转向诊断跟踪以获取简单的时序跟踪,因此我至少可以尝试找出原因并尝试缩小范围。

I'm quite happy to add 我很高兴添加

System.Diagnostics.Trace.WriteLine("....");

wherever necessary and add a listener (via web.config entry) to write out to a log file, but could this massively impact the performance of the live environment itself? 在需要的地方添加一个侦听器(通过web.config条目)以写出到日志文件,但这是否会对实时环境本身的性能产生重大影响?

Is there anything else I need to consider when, potentially, leaving this to run over the weekend? 我还有什么需要考虑的因素,可能在什么时候让它在周末运行? ie is it best that I specify how large the log file is to get before closing and opening a new one? 即最好在关闭和打开一个新文件之前指定日志文件要多大?

It depends how much data you are going to log so turn on the logger and check if your application behaves normally. 这取决于您要记录多少数据,因此请打开记录器并检查您的应用程序是否正常运行。 Also if logging to a log file slows down your application consider a faster TraceListener such as EventLogTraceListener (you may create a dedicated event log for this purpose with maximum size and log rolling). 另外,如果登录到日志文件会使您的应用程序变慢,请考虑使用速度更快的TraceListener(例如EventLogTraceListener)(您可以为此目的创建专用的事件日志,并以最大的大小滚动日志)。 In case logging to a file is not a problem get EssentialDiagnostics RollingFileTraceListener . 如果记录到文件不是问题,请获取EssentialDiagnostics RollingFileTraceListener It has many options including setting maximum file size and the number of rolled files. 它具有许多选项,包括设置最大文件大小和卷动文件数。

Use a logging framework like log4NET and make logging like: 使用类似log4NET的日志记录框架,并使记录如下:

LogManager.GetCurrentClassLogger().Debug("...");

When you disable logging afterwards in the configuration, these functions are not executed by the framework. 以后在配置中禁用日志记录时,框架不会执行这些功能。

If you need to do string formatting for your messages: Use "DebugFormat()" which will not do the formatting if it is not needed by the level of logging desired. 如果需要对消息进行字符串格式化:使用“ DebugFormat()”,如果所需的日志记录级别不需要格式化,则将不进行格式化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM