datalust / nlog-targets-seq

An NLog target that writes events to Seq. Built for NLog 4.5+.
https://getseq.net
Apache License 2.0
21 stars 11 forks source link

Support override of mapping from NLog LogLevel to Seq Level #75

Closed snakefoot closed 8 months ago

snakefoot commented 8 months ago

See also: https://github.com/datalust/seq-tickets/discussions/2117

<target xsi:type="Seq" serverUrl="http://localhost:5341" apiKey="" seqLevel="${event-properties:SubLevel:whenEmpty=${level}}" />

Then you can override the default LogLevel in Seq by specifying SubLevel like this:

logger.WithProperty("SubLevel", "Audit").Info("Hello, world!");

Or like this:

logger.Info("{SubLevel} Hello, world!", "Audit");
nblumhardt commented 8 months ago

Thanks for the PR, @snakefoot :+1:

Right now this seems a bit niche to deserve its own extension point here in the target - wondering if there's some way we could enable this but not have to carry a setting specifically for it? :thinking:

snakefoot commented 8 months ago

Since Seq supports any Level-value, then one might change NLog to output Microsoft Extension ILogger Loglevel (Thus Warning + Information). So it is not just for supporting SubLevel (But any custom LogLevel-format). Ex ${level:format=FullName}. See also: https://github.com/NLog/NLog/wiki/Level-Layout-Renderer

nblumhardt commented 8 months ago

Thanks for the follow-up; seems aligned with the NLog way of approaching it - works for me :+1:

NameOfTheDragon commented 7 months ago

@snakefoot I'm missing something on how this is supposed to work. I thought I understood it but now I come to use it I can't find the explanation that I thought I understood ;-) How do I tell NLog to write a log level other than it's built-in "cast-in-stone" levels?

nblumhardt commented 7 months ago

@NameOfTheDragon I think it should be something like:

logger.WithProperty("SubLevel", "Audit").Info("Hello, world!");

HTH, Nick