Nlog version: 4.6.7
Platform: .Net 4.7
Current NLog config (xml or C#, if relevant)
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogFile="c:/logs/nlog.log" internalLogLevel="Trace">
<variable name="facilityName" value="BppprCalc" />
<targets async="true">
<target name="graylogCounters" xsi:type="GraylogHttp" facility="${facilityName}" graylogServer="http://graylog" graylogPort="12201">
<parameter name="processor_total" layout="${performancecounter:Category=Processor:Counter=% Processor Time:Instance=_Total}" />
<parameter name="requests_per_second" layout="${performancecounter:Category=ASP.NET Apps v4.0.30319:Counter=Requests/Sec:Instance=${gdc:InstanceName}}" />
<parameter name="requests_in_queue" layout="${performancecounter:Category=ASP.NET Apps v4.0.30319:Counter=Requests in Application Queue:Instance=${gdc:InstanceName}}" />
<parameter name="errors_total_per_second" layout="${performancecounter:Category=ASP.NET Apps v4.0.30319:Counter=Errors Total/Sec:Instance=${gdc:InstanceName}}" />
</target>
</targets>
<rules>
<logger name="counters" level="debug" writeTo="graylogCounters" final="true"/>
</rules>
</nlog>
2019-08-30 13:19:16.5796 Warn Exception in layout renderer. Exception: System.InvalidOperationException: Экземпляр '${gdc' не существует в указанной категории.
в System.Diagnostics.CounterDefinitionSample.GetInstanceValue(String instanceName)
в System.Diagnostics.PerformanceCounter.NextSample()
в NLog.LayoutRenderers.PerformanceCounterLayoutRenderer.GetValue()
в NLog.LayoutRenderers.PerformanceCounterLayoutRenderer.Append(StringBuilder builder, LogEventInfo logEvent)
в NLog.LayoutRenderers.LayoutRenderer.RenderAppendBuilder(LogEventInfo logEvent, StringBuilder builder)
In english the result is the gdc do not exist in selected category.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogFile="c:/logs/nlog.log" internalLogLevel="Trace">
<variable name="facilityName" value="BppprCalc" />
<variable name="instanceName" value="DefaultInstance" />
<targets async="true">
<target name="graylogCounters" xsi:type="GraylogHttp" facility="${facilityName}" graylogServer="http://graylog" graylogPort="12201">
<parameter name="processor_total" layout="${performancecounter:Category=Processor:Counter=% Processor Time:Instance=_Total}" />
<parameter name="requests_per_second" layout="${performancecounter:Category=ASP.NET Apps v4.0.30319:Counter=Requests/Sec:Instance=${instanceName}}" />
<parameter name="requests_in_queue" layout="${performancecounter:Category=ASP.NET Apps v4.0.30319:Counter=Requests in Application Queue:Instance=${instanceName}}" />
<parameter name="errors_total_per_second" layout="${performancecounter:Category=ASP.NET Apps v4.0.30319:Counter=Errors Total/Sec:Instance=${instanceName}}" />
</target>
</targets>
<rules>
<logger name="counters" level="debug" writeTo="graylogCounters" final="true"/>
</rules>
</nlog>
code at startup
```c#
NLog.LogManager.Configuration.Variables["instanceName"] = "_LM_W3SVC_1_ROOT_BppprCalc";
NLog.LogManager.ReconfigExistingLoggers();
and there is another mistake
2019-08-30 14:04:12.7192 Warn Exception in layout renderer. Exception: System.InvalidOperationException: Экземпляр 'DefaultInstance' не существует в указанной категории.
в System.Diagnostics.CounterDefinitionSample.GetInstanceValue(String instanceName)
в System.Diagnostics.PerformanceCounter.NextSample()
в NLog.LayoutRenderers.PerformanceCounterLayoutRenderer.GetValue()
в NLog.LayoutRenderers.PerformanceCounterLayoutRenderer.Append(StringBuilder builder, LogEventInfo logEvent)
в NLog.LayoutRenderers.LayoutRenderer.RenderAppendBuilder(LogEventInfo logEvent, StringBuilder builder)
```
You have correctly spotted that Instance is not implemented with support for NLog Layout:
PullRequest is welcome.
Guess this is https://github.com/NLog/NLog/issues/1234 ?
Guess this is #1234 ?
Well implementing #1234 so it works great everywhere is not an easy task. Implementing good dynamic caching logic is not easy, when it has to perform and be predictable.
Also Layout loves to render string-objects, so problem solved here (Instance is a string). Think #1234 is about making it easy to also render other datatypes (bool + integer + enum + etc.).
Well, actually I tried to make a variable, set value and reconfigure the target in order to get right performance counter.
c#
NLog.LogManager.Configuration.Variables["instanceName"] = "_LM_W3SVC_1_ROOT_BppprCalc";
NLog.LogManager.ReconfigExistingLoggers();
But strange things happens. layout is wrong

but variable is ok

Well, actually I tried to make a variable, set value and reconfigure the target in order to get right performance counter.
You are very persistent in making this work, but the NLog-magic only works with Layout. And Instance is not implemented with support for NLog Layout:
PullRequest is welcome.
Created #3579 with example of how to implement NLog Layout magic.
Has your question being answered?
I assume your question has been answered, if not, please let us know!
@Kirya522 NLog ver. 4.6.8 has been released that allows NLog Layout-logic to work for the Instance-property: