mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
using System;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace ZeroLevel.Services.Logging
|
|
{
|
|
internal sealed class NoLimitedLogMessageBuffer : ILogMessageBuffer
|
|
{
|
|
private readonly BlockingCollection<Tuple<LogLevel, string>> _messageQueue =
|
|
new BlockingCollection<Tuple<LogLevel, string>>();
|
|
|
|
private bool _isDisposed = false;
|
|
|
|
public long Count
|
|
{
|
|
get
|
|
{
|
|
if (_messageQueue.IsCompleted)
|
|
return 0;
|
|
return _messageQueue.Count;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (!_isDisposed)
|
|
{
|
|
_isDisposed = true;
|
|
_messageQueue.Dispose();
|
|
}
|
|
}
|
|
|
|
public void Push(LogLevel level, string message)
|
|
{
|
|
if (_isDisposed) return;
|
|
_messageQueue.Add(new Tuple<LogLevel, string>(level, message));
|
|
}
|
|
|
|
public Tuple<LogLevel, string> Take()
|
|
{
|
|
return _messageQueue.Take();
|
|
}
|
|
}
|
|
} |