Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Add support for buffer count / inspection #41

Open
szalkerous opened this issue Feb 24, 2018 · 2 comments
Open

Add support for buffer count / inspection #41

szalkerous opened this issue Feb 24, 2018 · 2 comments

Comments

@szalkerous
Copy link

I have run into a situation where one of my appender's target data is being accessed before the buffer is emptied resulting in a loss of logging data.

It would be very handy to have a way to ask for a buffer/queue count, or a boolean flag to determine if the buffer/queue is empty.

This way I could block certain areas of my application until the logging queue is empty before trying to access that log data.

I realize there are ways around this, such as destroying the AsyncForwardingAppender and recreating it, but that seems to be a drastic approach to a simple problem.

My only other alternative is to fork the Log4net.Async project and modify it for my situation, but then it becomes orphaned code that I must maintain manually.

Thanks for your consideration.

@szalkerous
Copy link
Author

szalkerous commented Feb 24, 2018

If it's of any help, what I did for now was do a local fork and make the following changes:

IQueue.cs -- add int Count();
RingBuffer.cs -- add public int Count() {
AsyncForwardingAppenderBase.cs - add public abstract int BufferCount { get; }
AsyncForwardingAppender.cs - add

public override int BufferCount
{
   get { return buffer.Count(); }
}

and

public override bool Flush(int millisecondsTimeout)
{
	DateTime starttime = DateTime.Now;

	while (buffer.Count() != 0)
	{
		Thread.Sleep(10);
		
		if (shutDownRequested)
		{
			return false;
		}

		if (DateTime.Now.Subtract(starttime).TotalMilliseconds >= millisecondsTimeout)
		{
			return false;
		}
	}

	return true;
}

Not sure if there's a better way to do this, but I needed something for now.

@rcollette
Copy link
Collaborator

If you want lossless, why not use the ParallelForwardingAppender? Aside from that, what not create a pull request and a test for the code that you've already written?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants