简体   繁体   中英

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?

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). In case logging to a file is not a problem get 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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