In a previous blog post – Custom Layout Renderer for NLog using C#, I have mentioned about how to create a class inheriting LayoutRenderer and writing custom Layout Renderer.
This blog post talks about inheriting from WrapperLayoutRendererBase class.
The WrapperLayoutRendererBase class has a method with the signature:
protected override string Transform(string text)
This method needs to be overridden. The nice thing about using this class is other layout renderers can be used in combination.
Here is a GitHub repo implementing hash functions that can be used as LayoutRenderers.
https://github.com/ALightTechnologyAndServicesLimited/ALight.NLog.LayoutRenderer.Hash
The source code has 4 projects:
- The actual implementation
- Unit Tests
- Benchmark Tests
- Example
The usage is straightforward, use hash or securehash layout renderer.
<extensions>
<add assembly="ALight.NLog.LayoutRenderer.Hash" />
</extensions>
<target xsi:type="File" name="logfile" fileName="c:\temp\console-example.log"
layout="${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring} ${hash:hello}
${securehash:value=${level}} ${event-properties:item=secret} ${hash:${event-properties:item=secret}} ${hash:${level}}" />
The hash implementation is about 10 – 11 times faster but uses Murmur3 non cryptographic hash.
I might consider a nuget package at a later point, but not now, because the code is very minimal and like a small helper class.
–
Mr. Kanti Kalyan Arumilli
B.Tech, M.B.A
Founder & CEO, Lead Full-Stack .Net developer
ALight Technology And Services Limited
Phone / SMS / WhatsApp on the following 3 numbers:
+91-789-362-6688, +1-480-347-6849, +44-07718-273-964
+44-33-3303-1284 (Preferred number if calling from U.K, No WhatsApp)
kantikalyan@gmail.com, kantikalyan@outlook.com, admin@alightservices.com, kantikalyan.arumilli@alightservices.com, KArumilli2020@student.hult.edu, KantiKArumilli@outlook.com and 3 more rarely used email addresses – hardly once or twice a year.