I am using the latest version of NLog ( from nuget ) and I configure it programmatically.
Currently it saves in my database but I would like it to encrypt my stacktrace parameter.
Is there any way that NLog does this automatically?
Given that I have a simple function to encrypt the stacktrace is there an easy way to apply it?
I would suggest writing a LayoutRendererWrapper. A LayoutRendererWrapper allows you to “wrap” a LayoutRenderer so that you can apply processing to the output. In the case of encrypting the stack trace, you can configure NLog to add the StackTrace to the output, but you can wrap the StackTrace layout renderer so that you can apply your encryption.
You see examples of LayuoutRendererWrappers in NLog’s source code repository.
Actually, the general nature of the LayoutRendererWrapper means that you can write an encrypting wrapper and apply it to any LayoutRenderer. So, you could, for example, encrypt the stack trace and the message, but leave the rest of the fields as clear text.
Here is an example (untested) of how you might write an encrypting LayoutRendererWrapper:
I think it would be configured like this in the NLog.config file:
I’m not sure how you would configure it programmatically as I don’t normally use programmatic configuration.