Retrieve values from C# code into NLog.config file

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Retrieve values from C# code into NLog.config file

Leito
Hello,

Freshly new to NLog since today. Seems a great tool.

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

The reason I want to use a "variable" is to retrieve the password (that I use to log info in my database) previously entered by the user in a windows form.

Thx,
/Leito
Reply | Threaded
Open this post in threaded view
|

Re: Retrieve values from C# code into NLog.config file

Jarek Kowalski
Administrator
Sure. Look at ${gdc} or ${mdc} which let you access global or
per-thread values stored in a dictionary.

Jarek
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Retrieve values from C# code into NLog.config file

Leito
Exactly what I was looking for, thanks a lot. :)

But I'm not sure of my comprehension and the difference between gdc and mdc : mdc values will only exists in the class where they are created (so they willl cease to exist with the class), whereas gdc values will exist until the application exists, right ?