Skip to content

Commit a12b0c2

Browse files
niemyjskiejsmith
authored andcommitted
Optimized buffer checking & don't check file size if it's going to be truncated
1 parent 73d6a71 commit a12b0c2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Exceptionless/Logging/FileExceptionlessLog.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ public void Trace(string message, string source = null) {
117117
}
118118

119119
public void Flush() {
120-
if (_isFlushing || _buffer.Count == 0)
120+
if (_isFlushing || _buffer.IsEmpty)
121121
return;
122122

123-
if (DateTime.UtcNow.Subtract(_lastSizeCheck).TotalSeconds > 120)
123+
// Only check if appending file and size hasn't been checked in 2 minutes
124+
if ((_append || !_firstWrite) && DateTime.UtcNow.Subtract(_lastSizeCheck).TotalSeconds > 120)
124125
CheckFileSize();
125126

126-
if (_isFlushing)
127+
if (_isFlushing || _buffer.IsEmpty)
127128
return;
128129

129130
try {

test/Exceptionless.Tests/Log/FileExceptionlessLogTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public virtual async Task LogFlushTimerWorks() {
3131
string contents = log.GetFileContents();
3232
Assert.Equal("", contents);
3333

34-
await Task.Delay(TimeSpan.FromMilliseconds(3050));
34+
await Task.Delay(TimeSpan.FromMilliseconds(3100));
3535

3636
Assert.True(LogExists(log.FilePath));
3737
contents = log.GetFileContents();

0 commit comments

Comments
 (0)