imlokesh imlokesh - 2 months ago 25
C# Question

How to clear MemoryTarget Logs in NLog?

I'm using a Memory Target for logging.

<target xsi:type="Memory" name="memLog" layout="${longdate} - ${message}" />


This is a log heavy application and eventually the log becomes very large and the application runs out of memory.

Is there any way to reset the
MemoryTarget.Logs
collection? It is a read-only property.

Answer

The MemoryTarget.Logs property implements IList. Why not just clear it like this:

MemoryTarget.Logs.Clear();