I am running a .net application in a windows docker container with Docker Desktop for Windows. When my app tries to create perf counters using this code:
_counter = new PerformanceCounter(categoryName, counterName, InstanceName, true);
//My categoryname is Processor , CounterName is % Processor Time & instancename is _Total.
I am getting this exception:
Unhandled Exception: System.InvalidOperationException: Category does not exist. at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter) at System.Diagnostics.PerformanceCounter.InitializeImpl() at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
This is the base image of my container: https://hub.docker.com/r/microsoft/dotnet-framework/
It has Windows Server core as part of it.
Appreciate any help in fixing this. I am not sure if this is just some windows setting I need to change here or is it because of the docker & windows or my code not able to access the categories of the perf counters.
It is working perfectly fine, when I run it in my local machine instead of a container.