I want to write a stand alone string (like a horizontal line or delimiter) to the log file.
If I use
string delimiter = "------------------------------------------------";
_logger.Info(delimiter);
then in the log file I get:
2013-01-08 15:58:54.4008 INFO ------------------------------------------------
I do not want the extra information at the beginning of the line.
Is there a way to write a separator like this with NLog? I checked the NLog wiki, but didn’t find anything.
See my answer to a similar question here:
Nlog – Generating Header Section for a log file
To summarize, I propose defining another logging target. If you are logging to a file, define a second file target, pointing to the same file, but with a different layout. Define the layout so that it has the format that you want. You could define the layout to be hardcoded to the header value that you want (“—————” in your case), or your could define the layout to only log the message and then you could pass the layout to it.
Here is the shortest thing that might work. Note, I cut and pasted from the answer linked above and modified slightly for your case. I did not test it.
Define the layouts:
Define the targets using the layouts:
Define the rules/loggers:
Use the loggers:
Alternatively, you could define the layout such that it has the header definition in it:
Then you would use it like this:
You could write a helper function so that you don’t have to deal explicitly with the header logger:
I think that this should give you some good insight into how you can accomplish what you are trying to do.
Hope this helps!
Good luck!