18

Does .NET have something similar to Java's garbage collection log? I want to write GC stats to a log in a production application. Google doesn't tell my anything useful and SO doesn't seem to have any related questions either.

Thanks

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Shahbaz
  • 10,395
  • 21
  • 54
  • 83
  • Additionally, I need these logs generated on my client's machines. Every once in a while I will collect the logs and analyze GC performance (when gc ran, how many milliseconds it took, not much more info than that) – Shahbaz Jan 09 '10 at 03:31

4 Answers4

6

GC stats are available as performance counters. In perfmon they're displayed under the ".NET CLR Memory" category. You can access perf counters programmatically via the System.Diagnostics namespace (the PerformanceCounterXxx classes), or use Server Explorer to create handy wrappers.

Note that these are statistics and do not provide detailed per-object logging.

itowlson
  • 73,686
  • 17
  • 161
  • 157
3

When the perf stats tell you there's a problem, you can dive in with a debugger (windbg) to find leaks. The !GCRoot command allows you to find out why memory isn't being collected. See this blogpost for more info

Sander Rijken
  • 21,376
  • 3
  • 61
  • 85
0

You can set up some level of GC logging yourself using Garbage Collection Notifications. But note that if you're using the ConcurrentGC, which would be typical for server-side applications, you only get notifications for stop-the-world GCs. So it's not as complete as the Java equivalent, but it's something.

There is also quite a bit of GC related info available via ETW logging. It is probably possible to wire up your own ETW listener and extract information that way, but I don't know of a pre-baked method to do that.

Brian Reischl
  • 7,216
  • 2
  • 35
  • 46
0

For new dotnet application I would consider to use GC.GetGCMemoryInfo() method, which has a lot of different telemetry regarding GC.

Denis
  • 3,595
  • 12
  • 52
  • 86