@@ -48,6 +48,7 @@ public static class FileLoggerConfigurationExtensions
4848 /// <param name="buffered">Indicates if flushing to the output file can be buffered or not. The default
4949 /// is false.</param>
5050 /// <param name="shared">Allow the log file to be shared by multiple processes. The default is false.</param>
51+ /// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param>
5152 /// <returns>Configuration object allowing method chaining.</returns>
5253 /// <remarks>The file will be written using the UTF-8 character set.</remarks>
5354 public static LoggerConfiguration File (
@@ -59,14 +60,15 @@ public static LoggerConfiguration File(
5960 long ? fileSizeLimitBytes = DefaultFileSizeLimitBytes ,
6061 LoggingLevelSwitch levelSwitch = null ,
6162 bool buffered = false ,
62- bool shared = false )
63+ bool shared = false ,
64+ TimeSpan ? flushToDiskInterval = null )
6365 {
6466 if ( sinkConfiguration == null ) throw new ArgumentNullException ( nameof ( sinkConfiguration ) ) ;
6567 if ( path == null ) throw new ArgumentNullException ( nameof ( path ) ) ;
6668 if ( outputTemplate == null ) throw new ArgumentNullException ( nameof ( outputTemplate ) ) ;
6769
6870 var formatter = new MessageTemplateTextFormatter ( outputTemplate , formatProvider ) ;
69- return File ( sinkConfiguration , formatter , path , restrictedToMinimumLevel , fileSizeLimitBytes , levelSwitch , buffered : buffered , shared : shared ) ;
71+ return File ( sinkConfiguration , formatter , path , restrictedToMinimumLevel , fileSizeLimitBytes , levelSwitch , buffered : buffered , shared : shared , flushToDiskInterval : flushToDiskInterval ) ;
7072 }
7173
7274 /// <summary>
@@ -75,7 +77,7 @@ public static LoggerConfiguration File(
7577 /// <param name="sinkConfiguration">Logger sink configuration.</param>
7678 /// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into
7779 /// text for the file. If control of regular text formatting is required, use the other
78- /// overload of <see cref="File(LoggerSinkConfiguration, string, LogEventLevel, string, IFormatProvider, long?, LoggingLevelSwitch, bool, bool)"/>
80+ /// overload of <see cref="File(LoggerSinkConfiguration, string, LogEventLevel, string, IFormatProvider, long?, LoggingLevelSwitch, bool, bool, TimeSpan? )"/>
7981 /// and specify the outputTemplate parameter instead.
8082 /// </param>
8183 /// <param name="path">Path to the file.</param>
@@ -89,6 +91,7 @@ public static LoggerConfiguration File(
8991 /// <param name="buffered">Indicates if flushing to the output file can be buffered or not. The default
9092 /// is false.</param>
9193 /// <param name="shared">Allow the log file to be shared by multiple processes. The default is false.</param>
94+ /// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param>
9295 /// <returns>Configuration object allowing method chaining.</returns>
9396 /// <remarks>The file will be written using the UTF-8 character set.</remarks>
9497 public static LoggerConfiguration File (
@@ -99,9 +102,10 @@ public static LoggerConfiguration File(
99102 long ? fileSizeLimitBytes = DefaultFileSizeLimitBytes ,
100103 LoggingLevelSwitch levelSwitch = null ,
101104 bool buffered = false ,
102- bool shared = false )
105+ bool shared = false ,
106+ TimeSpan ? flushToDiskInterval = null )
103107 {
104- return ConfigureFile ( sinkConfiguration . Sink , formatter , path , restrictedToMinimumLevel , fileSizeLimitBytes , levelSwitch , buffered : buffered , shared : shared ) ;
108+ return ConfigureFile ( sinkConfiguration . Sink , formatter , path , restrictedToMinimumLevel , fileSizeLimitBytes , levelSwitch , buffered : buffered , shared : shared , flushToDiskInterval : flushToDiskInterval ) ;
105109 }
106110
107111 /// <summary>
@@ -169,7 +173,8 @@ static LoggerConfiguration ConfigureFile(
169173 LoggingLevelSwitch levelSwitch = null ,
170174 bool buffered = false ,
171175 bool propagateExceptions = false ,
172- bool shared = false )
176+ bool shared = false ,
177+ TimeSpan ? flushToDiskInterval = null )
173178 {
174179 if ( addSink == null ) throw new ArgumentNullException ( nameof ( addSink ) ) ;
175180 if ( formatter == null ) throw new ArgumentNullException ( nameof ( formatter ) ) ;
@@ -212,6 +217,11 @@ static LoggerConfiguration ConfigureFile(
212217 return addSink ( new NullSink ( ) , LevelAlias . Maximum , null ) ;
213218 }
214219
220+ if ( flushToDiskInterval . HasValue )
221+ {
222+ sink = new PeriodicFlushToDiskSink ( sink , flushToDiskInterval . Value ) ;
223+ }
224+
215225 return addSink ( sink , restrictedToMinimumLevel , levelSwitch ) ;
216226 }
217227 }
0 commit comments