NLogViewer
NLogViewer copied to clipboard
Implementing in code (not nlog.confg)
I've been wrestling with implementing this for the past little while (trying to adapt the instructions for nlog.config to their in-code equivalents) but can't seem to get it right.
In particular, I'm struggling with the equivalents for:
- adding the assembly/extension (would adapting this be right? https://stackoverflow.com/questions/30340414/nlog-extensions-add-assembly-programmatically)
- setting async to true for targets
- adding a target of type CacheTarget
Do you have any pointers? I've been looking through the NLog documentation and searching online for a bit but haven't found much help except for that link regarding the assembly loading.
Hello,
Have you found a solution in the meantime or is the issue still relevant?
The project I was implementing this in isn't something I've worked on recently (so I don't remember exact details), but I believe I was able to figure out the first and third points, and simply gave up on implementing the second because I couldn't find a solution (and it wasn't critically important to implement for me). I imagine that it's something that could still be done though.
For 1), adapting the information in that link did seem to be the solution. I implemented:
var assembly = Assembly.Load("NLogViewer");
NLog.Config.ConfigurationItemFactory.Default.RegisterItemsFromAssembly(assembly);
For 3), I implemented:
DJ.Targets.CacheTarget CacheTarget = new DJ.Targets.CacheTarget();//the important part of this is this line
config.AddRule(LogLevel.Debug, LogLevel.Fatal, CacheTarget);//this line is just additional context, rather than the solution itself
and I think that did what I wanted.