I'm quite new at working with NLog.
, but I have earlier experience working with logfiles/trace files, but previously the logs looked as follows:
<timestamp> ... | main function logging
<timestamp> ... | sub function logging.1
<timestamp> ... | subsub function logging.1.1
<timestamp> ... | subsub function logging.1.2
<timestamp> ... | sub function logging.2
<timestamp> ... | subsub function logging.2.1
<timestamp> ... | subsubsub function logging.2.1.1
...
As you can see, the indenting was done, based on the depth within the callstack.
In NLog
technology (NLog.xml
file), I have seen a depth
attribute, but I believe this is only meant for limiting the amount of logs, based on the callstack depth, I don't see any indentation configuration.
Does NLog
have that feature, where indentation is added, based on the callstack depth?
new StackTrace()
is not cheap. – HamitosemiticNLog
and if yes, in which version? – SeineNLog
feature. However, as you say, indenting code is typical for single-threaded code with only synchronous requests (I worked in that before). However now I work in a multi-threaded environment with asynchronous requests, so indenting might cause weird indentation jumps, so my question is senseless. You can write your comment as an answer (with references to the other posts for reference reasons), I'll accept the answer and give you the bounty. – SeineStackTrace
with the same perfomance drop. You can try something like this to reduce that drop - https://mcmap.net/q/781544/-for-c-logging-how-do-i-obtain-the-call-stack-depth-with-minimal-overhead/5311735 (while NLog itself cannot afford to use such hacks). But yeah, async-generated junk frames will likely kill this idea, unless you can filter them out, but for that you will need full stack trace (not just depth), which again gets us back to perfomance issues. – HamitosemiticNLog
application "subscribed" to the main application, keeping track of the stacktrace, but that's probably a question too far :-) – Seine