-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathLogBuffer.cs
More file actions
123 lines (91 loc) · 2.6 KB
/
LogBuffer.cs
File metadata and controls
123 lines (91 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using ColumnizerLib;
using NLog;
namespace LogExpert.Core.Classes.Log;
public class LogBuffer
{
#region Fields
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
#if DEBUG
private readonly IList<long> _filePositions = []; // file position for every line
#endif
private readonly List<ILogLineMemory> _lineList = [];
private int MAX_LINES = 500;
private long _size;
#endregion
#region cTor
//public LogBuffer() { }
// Don't use a primary constructor here: field initializers (like MAX_LINES) run before primary constructor parameters are assigned,
// so MAX_LINES would always be set to its default value before the constructor body can assign it. Use a regular constructor instead.
public LogBuffer (ILogFileInfo fileInfo, int maxLines)
{
FileInfo = fileInfo;
MAX_LINES = maxLines;
}
#endregion
#region Properties
public long StartPos { set; get; }
public long Size
{
set
{
_size = value;
#if DEBUG
if (_filePositions.Count > 0)
{
if (_size < _filePositions[_filePositions.Count - 1] - StartPos)
{
_logger.Error("LogBuffer overall Size must be greater than last line file position!");
}
}
#endif
}
get => _size;
}
public int EndLine => StartLine + LineCount;
public int StartLine { set; get; }
public int LineCount { get; private set; }
public bool IsDisposed { get; private set; }
public ILogFileInfo FileInfo { get; set; }
public int DroppedLinesCount { get; set; }
public int PrevBuffersDroppedLinesSum { get; set; }
#endregion
#region Public methods
public void AddLine (ILogLineMemory lineMemory, long filePos)
{
_lineList.Add(lineMemory);
#if DEBUG
_filePositions.Add(filePos);
#endif
LineCount++;
IsDisposed = false;
}
public void ClearLines ()
{
_lineList.Clear();
LineCount = 0;
}
public void DisposeContent ()
{
_lineList.Clear();
IsDisposed = true;
#if DEBUG
DisposeCount++;
#endif
}
public ILogLineMemory GetLineMemoryOfBlock (int num)
{
return num < _lineList.Count && num >= 0
? _lineList[num]
: null;
}
#endregion
#if DEBUG
public long DisposeCount { get; private set; }
public long GetFilePosForLineOfBlock (int line)
{
return line >= 0 && line < _filePositions.Count
? _filePositions[line]
: -1;
}
#endif
}