Questions tagged [system.diagnostics]

System.Diagnostics is a namespace of the .NET framework. It provides classes that allow you to interact with system processes, event logs, and performance counters.

System.Diagnostics is a namespace of the .NET framework. It provides classes that allow you to interact with system processes, event logs, and performance counters.

References

670 questions
633
votes
18 answers

How can I find the method that called the current method?

When logging in C#, how can I learn the name of the method that called the current method? I know all about System.Reflection.MethodBase.GetCurrentMethod(), but I want to go one step beneath this in the stack trace. I've considered parsing the stack…
flipdoubt
  • 13,897
  • 15
  • 64
  • 96
79
votes
7 answers

Can Stopwatch be used in production code?

I need an accurate timer, and DateTime.Now seems not accurate enough. From the descriptions I read, System.Diagnostics.Stopwatch seems to be exactly what I want. But I have a phobia. I'm nervous about using anything from System.Diagnostics in…
Adrian
  • 793
  • 1
  • 5
  • 5
74
votes
6 answers

System.Diagnostics.Debug.WriteLine in production code

I should probably know this already, but I'm not sure and I don't see it documented. I use System.Diagnostics.Debug.WriteLine quite often during the development process to be able to track changes to variables or exceptions as I'm debugging the…
David
  • 72,686
  • 18
  • 132
  • 173
59
votes
13 answers

How can I programmatically limit my program's CPU usage to below 70%?

Of late, I'm becoming more health oriented when constructing my program, I have observed that most of programs take 2 or 3 minutes to execute and when I check on the task scheduler, I see that they consume 100% of CPU usage, can I limit this usage…
Nidhi
  • 667
  • 3
  • 8
  • 12
46
votes
4 answers

Difference between ElapsedTicks, ElapsedMilliseconds, Elapsed.Milliseconds and Elapsed.TotalMilliseconds? (C#)

I'm totally confused between these 4. What is the difference between ElapsedMilliseconds (long), ElapsedTicks (long), Elapsed.TotalMilliseconds (double) and Elapsed.Milliseconds (int)? I have a function { Stopwatch sw = new…
nawfal
  • 70,104
  • 56
  • 326
  • 368
42
votes
6 answers

When should I use Tracing vs Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics?

How do I choose between standard tracing, Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics? Is there a situation where one is more appropriate than the other? ... what would that be? (ASP.NET, console app, Azure Cloud, SOHO,…
makerofthings7
  • 60,103
  • 53
  • 215
  • 448
41
votes
4 answers

How to get the output of a System.Diagnostics.Process?

I run ffmpeg like this: System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo = new System.Diagnostics.ProcessStartInfo(ffmpegPath, myParams); p.Start(); p.WaitForExit(); ... but the problem is that the console with ffmpeg…
marcgg
  • 65,020
  • 52
  • 178
  • 231
39
votes
3 answers

Using PerformanceCounter to track memory and CPU usage per process?

How can I use System.Diagnostics.PerformanceCounter to track the memory and CPU usage for a process?
Louis Rhys
  • 34,517
  • 56
  • 153
  • 221
35
votes
4 answers

Difference between Debugger.Launch and Debugger.Break

What's the difference between Debugger.Launch(); Debugger.Break(); ?
Nissim
  • 6,395
  • 5
  • 49
  • 74
34
votes
2 answers

Difference between using Trace and TraceSource

Anyone knows the difference between System.Diagnostic.Trace and System.Diagnostic.TraceSource classes? I've been using Trace for most of my projects and I just happen to found out about TraceSource the other day. They seems to offer similar API, is…
oscarkuo
  • 10,431
  • 6
  • 49
  • 62
33
votes
3 answers

"Gracefully" killing a process

Right now I am using Process.Kill() to kill a process. Is there a way though, instead of just killing it immediately, that I can like send a message to the process instructing it to close so that it can gracefully clean up and shut down. Basically,…
Icemanind
  • 47,519
  • 50
  • 171
  • 296
31
votes
5 answers

How to translate MS Windows OS version numbers into product names in .NET?

How to translate MS Windows OS version numbers into product names? For example, in .NET the following two properties could be used to work out that the product is MS Windows Vista Ultimate Edition : Environment.OSVersion.Platform returns…
Thomas Bratt
  • 48,038
  • 36
  • 121
  • 139
25
votes
1 answer

Trace logs location, where to view them

Where do you see Trace.Write(""); logs while developing an MVC or WCF app? What is the correct place to look at?
DarthVader
  • 52,984
  • 76
  • 209
  • 300
24
votes
2 answers

How do I know when the last OutputDataReceived has arrived?

I have a System.Diagnostics.Process object in a program targeted at the .Net framework 3.5 I have redirected both StandardOutput and StandardError pipes and I'm receiving data from them asynchronously. I've also set an event handler for the Exited…
Elggarc
24
votes
4 answers

Format of Tracing output in System.Diagnostics.TraceSource

The following code: static void Main(string[] args) { TraceSource ts = new TraceSource("MyApplication"); ts.Switch = new SourceSwitch("MySwitch"); ts.Switch.Level = SourceLevels.All; ts.Listeners.Add(new…
Flagg1980
  • 295
  • 1
  • 2
  • 7
1
2 3
44 45