I am using NLog to log to a RabbitMQ message queue and have written my own Log Target to achieve this.
At the end of my process I call LogManager.Shutdown() to free up all unmanaged resources.
To test the performance of my logger I have implement a loop over 1000 items and each is published to my message queue. I am using asynchronous logging.
The first problem I had is that when my application gets to the end of its processing and calls LogManager.ShutDown, all threads were teminated and I found I was loosing a lot of messages before they got written to my message queue.
I then modified my code to look like this....
LogManager.Shutdown()
The problem I have now is that Flush() doesn't seem to block the main thread until all of the asynchronous messages have been written.
I have tried adding a time out to flush of say 1 minute which should be enough for my application to finish processing. However, I noticed that once all of the logs had been written, my application still waited for the full 1 minute before shutting down.
I also tried adding my own AsyncContinuation but I am not really sure what this should look like or if it is the right approach to this problem.
1. Is this the expected behaviour that Flush() should block the thread ?
2. Is there a way to make sure that Flush() cleans out all of the messages from my log targets before my application shuts down the logger?
3. Can I do something with the continuation to achieve this?
I would appreciate some help as I need to have asynchronous logging without loosing messages.
Thanks in advance.