Get values ​​from C # code to NLog.config file

Is it possible to use "variables" in the NLog.config configuration NLog.config to get values ​​from some C # code?

The reason I want to use the "variable" is to get the password (which I use to register information in my database) previously entered by the user in the form of a window.

+6
source share
1 answer

I found the answer:

I need to use the Global Diagnostics Context class:

  • In C # code, set the variable: GlobalDiagnosticsContext.Set("myVariableName", "myValue");
  • In the NLog.config file, access to the variable: ${gdc:item=myVariableName} gives me "myValue"
+9
source

Source: https://habr.com/ru/post/892684/


All Articles