public void Increment() { if (_isValid) { try { _counter.Increment(); } catch (Exception e) { PerformanceCounterWrapper.TraceException("increment", "counter increment failed.", e); } } }
public void SetRawValue(long value) { if (_isValid) { try { _counter.RawValue = value; } catch (Exception e) { PerformanceCounterWrapper.TraceException("SetRawValue", "failed to set raw value", e); } } }
public PerformanceCounterWrapper(string categoryName, string instanceName, string counterName) { _isValid = false; this._categoryName = categoryName; this._instanceName = instanceName; this._counterName = counterName; #if NETFRAMEWORK // Check if counter exists in the specified category and then create its instance if (PerformanceCounterCategory.CounterExists(_counterName, _categoryName)) { try { _counter = new PerformanceCounter(); _counter.InstanceLifetime = PerformanceCounterInstanceLifetime.Process; _counter.CategoryName = _categoryName; _counter.InstanceName = _instanceName; _counter.CounterName = _counterName; _counter.ReadOnly = false; _counter.RawValue = 0; _isValid = true; } catch (Exception e) { PerformanceCounterWrapper.TraceException("initialize", "Performance counter initialization failed, no data will be collected.", e); } } else { Tracer.TraceWarning( TraceSourceConstants.ComponentNames.PerfCounter, "initialize", "Performance counter {0} does not exist in shard management catagory.", counterName); } #endif }