Re: Custom Layouts Based on Log Level
You should be able to have two targets that write to exactly the same file (use concurrentWrites="true").
If you want to write a layout renderer, it should be pretty easy to write something like a ${if-level} layout renderer, that would wrap existing renderer and display its output only when level is <= designed.
The usage would be like:
${if-level:lowerThan=Debug:then=${stacktrace}:else=trace not included}
You can use ${rot13} (src/NLog/LayoutRenderers/Rot13.cs) as an example of a layout renderer that delegates to another renderer to do its job.
I'm thinking that you could even re-use NLog conditions parser for that (see "src/NLog/Conditions/" directory in the source), so that you can have a generic ${if} support:
${if:condition=level<=Debug:then=${stacktrace}}
That should be doable. Let us know how it goes.
|