2

I have a NLog memory target like described in this SO question.

My application processes the log messages itself:

var target = (MemoryTarget) LogManager.Configuration.FindTargetByName("memory");
IList<LogEntry> entries = target.Logs.Select(ParseLogEntry).ToList();
target.Logs.Clear();
...

However, from time to time, I get an InvalidOperationException, since a log entry arrives just when I am processing it.

Since this is multithreading, I know I need to synchronize access to the collection. In order to do so, I need to use a lock statement on something where NLog also uses lock. Does such a lock-object exist in NLog?

Community
  • 1
  • 1
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222

0 Answers0