I haven't found a solution for the problem yet. In some cases I have errors in my application that I have to log to a seperated log file. The problem with some of these errors is that they consists of a lot of data and I'd like to have the log entries in seperated files to analyze them later. Currently I just log the message to the global log file and copy and paste the start and end tags (XML, JSON) of the log entries manually to a different file, save it and open it in a JSON/XML-viewer. I think best would be to have a directory with unique file names to write for every log entry and have a back reference to the global log file with this file name as a log entry. But that's just my humble opinion, maybe there is a better solution for it. You have one? :)
Currently I am using NLog but I could also image to change to Serilog if this isn't possible with NLog. I also would say that there shouldn't be a different way to log the message in code than this:
public class TestClass
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private void Work()
{
var json/xml = ...
Log.Error(json/xml);
}
}
Because it's concern of the logging configuration how this is written to files, database etc.
Thanks.
The easy solution is just doing this (Ensures the Blob-output suddenly doesn't propagate some where unwanted):
Then do this in you NLog.config, where
${event-properties:BlobGuid}
ensures new file:There are a lot of ways to add context to a LogEvent. See also https://github.com/NLog/NLog/wiki/Context
The LogEvent context can be used in the logging rules filtering. See also https://github.com/nlog/NLog/wiki/Filtering-log-messages
You can also use the LogEvent-context in NLog Layouts, and FileTarget Filename is a NLog Layout. So the same file-target can write to different filenames based on LogEvent-context.