File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,6 @@ public static LoggerConfiguration File(
138
138
/// including the current log file. For unlimited retention, pass null. The default is 31.</param>
139
139
/// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param>
140
140
/// <returns>Configuration object allowing method chaining.</returns>
141
- /// <remarks>The file will be written using the UTF-8 character set.</remarks>
142
141
[ Obsolete ( "New code should not be compiled against this obsolete overload" ) , EditorBrowsable ( EditorBrowsableState . Never ) ]
143
142
public static LoggerConfiguration File (
144
143
this LoggerSinkConfiguration sinkConfiguration ,
@@ -239,7 +238,6 @@ public static LoggerConfiguration File(
239
238
/// Ignored if <paramref see="rollingInterval"/> is <see cref="RollingInterval.Infinite"/>.
240
239
/// The default is to retain files indefinitely.</param>
241
240
/// <returns>Configuration object allowing method chaining.</returns>
242
- /// <remarks>The file will be written using the UTF-8 character set.</remarks>
243
241
public static LoggerConfiguration File (
244
242
this LoggerSinkConfiguration sinkConfiguration ,
245
243
string path ,
Original file line number Diff line number Diff line change @@ -191,15 +191,11 @@ void ApplyRetentionPolicy(string currentFilePath)
191
191
var newestFirst = _roller
192
192
. SelectMatches ( potentialMatches )
193
193
. OrderByDescending ( m => m . DateTime )
194
- . ThenByDescending ( m => m . SequenceNumber )
195
- . Select ( m => new { m . Filename , m . DateTime } ) ;
194
+ . ThenByDescending ( m => m . SequenceNumber ) ;
196
195
197
196
var toRemove = newestFirst
198
197
. Where ( n => StringComparer . OrdinalIgnoreCase . Compare ( currentFileName , n . Filename ) != 0 )
199
- . SkipWhile ( ( x , i ) => ( i < ( _retainedFileCountLimit - 1 ?? 0 ) ) &&
200
- ( ! _retainedFileTimeLimit . HasValue ||
201
- x . DateTime . HasValue &&
202
- DateTime . Now . Subtract ( _retainedFileTimeLimit . Value ) . CompareTo ( x . DateTime . Value ) <= 0 ) )
198
+ . SkipWhile ( FilterFiles )
203
199
. Select ( x => x . Filename )
204
200
. ToList ( ) ;
205
201
@@ -217,6 +213,17 @@ void ApplyRetentionPolicy(string currentFilePath)
217
213
}
218
214
}
219
215
216
+ private bool FilterFiles ( RollingLogFile file , int index )
217
+ {
218
+ var isInCountLimit = index < ( _retainedFileCountLimit - 1 ?? 0 ) ;
219
+
220
+ var isInTimeLimit = ! _retainedFileTimeLimit . HasValue ;
221
+ if ( _retainedFileTimeLimit . HasValue && file . DateTime . HasValue )
222
+ isInTimeLimit = DateTime . Now . Subtract ( _retainedFileTimeLimit . Value ) . CompareTo ( file . DateTime . Value ) <= 0 ;
223
+
224
+ return isInCountLimit && isInTimeLimit ;
225
+ }
226
+
220
227
public void Dispose ( )
221
228
{
222
229
lock ( _syncRoot )
You can’t perform that action at this time.
0 commit comments