|
24 | 24 | using Serilog.Formatting.Json;
|
25 | 25 | using Serilog.Sinks.File;
|
26 | 26 |
|
27 |
| -// ReSharper disable MethodOverloadWithOptionalParameter |
| 27 | +// ReSharper disable RedundantArgumentDefaultValue, MethodOverloadWithOptionalParameter |
28 | 28 |
|
29 | 29 | namespace Serilog
|
30 | 30 | {
|
@@ -69,10 +69,8 @@ public static LoggerConfiguration File(
|
69 | 69 | bool shared,
|
70 | 70 | TimeSpan? flushToDiskInterval)
|
71 | 71 | {
|
72 |
| - // ReSharper disable once RedundantArgumentDefaultValue |
73 | 72 | return File(sinkConfiguration, path, restrictedToMinimumLevel, outputTemplate, formatProvider, fileSizeLimitBytes,
|
74 |
| - levelSwitch, buffered, shared, flushToDiskInterval, RollingInterval.Infinite, false, |
75 |
| - null, null); |
| 73 | + levelSwitch, buffered, shared, flushToDiskInterval, RollingInterval.Infinite, false, null, null, null); |
76 | 74 | }
|
77 | 75 |
|
78 | 76 | /// <summary>
|
@@ -110,9 +108,103 @@ public static LoggerConfiguration File(
|
110 | 108 | bool shared,
|
111 | 109 | TimeSpan? flushToDiskInterval)
|
112 | 110 | {
|
113 |
| - // ReSharper disable once RedundantArgumentDefaultValue |
114 | 111 | return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch,
|
115 |
| - buffered, shared, flushToDiskInterval, RollingInterval.Infinite, false, null, null); |
| 112 | + buffered, shared, flushToDiskInterval, RollingInterval.Infinite, false, null, null, null); |
| 113 | + } |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// Write log events to the specified file. |
| 117 | + /// </summary> |
| 118 | + /// <param name="sinkConfiguration">Logger sink configuration.</param> |
| 119 | + /// <param name="path">Path to the file.</param> |
| 120 | + /// <param name="restrictedToMinimumLevel">The minimum level for |
| 121 | + /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> |
| 122 | + /// <param name="levelSwitch">A switch allowing the pass-through minimum level |
| 123 | + /// to be changed at runtime.</param> |
| 124 | + /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> |
| 125 | + /// <param name="outputTemplate">A message template describing the format used to write to the sink. |
| 126 | + /// the default is "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}".</param> |
| 127 | + /// <param name="fileSizeLimitBytes">The approximate maximum size, in bytes, to which a log file will be allowed to grow. |
| 128 | + /// For unrestricted growth, pass null. The default is 1 GB. To avoid writing partial events, the last event within the limit |
| 129 | + /// will be written in full even if it exceeds the limit.</param> |
| 130 | + /// <param name="buffered">Indicates if flushing to the output file can be buffered or not. The default |
| 131 | + /// is false.</param> |
| 132 | + /// <param name="shared">Allow the log file to be shared by multiple processes. The default is false.</param> |
| 133 | + /// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param> |
| 134 | + /// <param name="rollingInterval">The interval at which logging will roll over to a new file.</param> |
| 135 | + /// <param name="rollOnFileSizeLimit">If <code>true</code>, a new file will be created when the file size limit is reached. Filenames |
| 136 | + /// will have a number appended in the format <code>_NNN</code>, with the first filename given no number.</param> |
| 137 | + /// <param name="retainedFileCountLimit">The maximum number of log files that will be retained, |
| 138 | + /// including the current log file. For unlimited retention, pass null. The default is 31.</param> |
| 139 | + /// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param> |
| 140 | + /// <returns>Configuration object allowing method chaining.</returns> |
| 141 | + [Obsolete("New code should not be compiled against this obsolete overload"), EditorBrowsable(EditorBrowsableState.Never)] |
| 142 | + public static LoggerConfiguration File( |
| 143 | + this LoggerSinkConfiguration sinkConfiguration, |
| 144 | + string path, |
| 145 | + LogEventLevel restrictedToMinimumLevel, |
| 146 | + string outputTemplate, |
| 147 | + IFormatProvider formatProvider, |
| 148 | + long? fileSizeLimitBytes, |
| 149 | + LoggingLevelSwitch levelSwitch, |
| 150 | + bool buffered, |
| 151 | + bool shared, |
| 152 | + TimeSpan? flushToDiskInterval, |
| 153 | + RollingInterval rollingInterval, |
| 154 | + bool rollOnFileSizeLimit, |
| 155 | + int? retainedFileCountLimit, |
| 156 | + Encoding encoding) |
| 157 | + { |
| 158 | + return File(sinkConfiguration, path, restrictedToMinimumLevel, outputTemplate, formatProvider, fileSizeLimitBytes, levelSwitch, buffered, |
| 159 | + shared, flushToDiskInterval, rollingInterval, rollOnFileSizeLimit, retainedFileCountLimit, encoding, null); |
| 160 | + } |
| 161 | + |
| 162 | + /// <summary> |
| 163 | + /// Write log events to the specified file. |
| 164 | + /// </summary> |
| 165 | + /// <param name="sinkConfiguration">Logger sink configuration.</param> |
| 166 | + /// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into |
| 167 | + /// text for the file. If control of regular text formatting is required, use the other |
| 168 | + /// overload of <see cref="File(LoggerSinkConfiguration, string, LogEventLevel, string, IFormatProvider, long?, LoggingLevelSwitch, bool, bool, TimeSpan?, RollingInterval, bool, int?, Encoding, FileLifecycleHooks)"/> |
| 169 | + /// and specify the outputTemplate parameter instead. |
| 170 | + /// </param> |
| 171 | + /// <param name="path">Path to the file.</param> |
| 172 | + /// <param name="restrictedToMinimumLevel">The minimum level for |
| 173 | + /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> |
| 174 | + /// <param name="levelSwitch">A switch allowing the pass-through minimum level |
| 175 | + /// to be changed at runtime.</param> |
| 176 | + /// <param name="fileSizeLimitBytes">The approximate maximum size, in bytes, to which a log file will be allowed to grow. |
| 177 | + /// For unrestricted growth, pass null. The default is 1 GB. To avoid writing partial events, the last event within the limit |
| 178 | + /// will be written in full even if it exceeds the limit.</param> |
| 179 | + /// <param name="buffered">Indicates if flushing to the output file can be buffered or not. The default |
| 180 | + /// is false.</param> |
| 181 | + /// <param name="shared">Allow the log file to be shared by multiple processes. The default is false.</param> |
| 182 | + /// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param> |
| 183 | + /// <param name="rollingInterval">The interval at which logging will roll over to a new file.</param> |
| 184 | + /// <param name="rollOnFileSizeLimit">If <code>true</code>, a new file will be created when the file size limit is reached. Filenames |
| 185 | + /// will have a number appended in the format <code>_NNN</code>, with the first filename given no number.</param> |
| 186 | + /// <param name="retainedFileCountLimit">The maximum number of log files that will be retained, |
| 187 | + /// including the current log file. For unlimited retention, pass null. The default is 31.</param> |
| 188 | + /// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param> |
| 189 | + /// <returns>Configuration object allowing method chaining.</returns> |
| 190 | + [Obsolete("New code should not be compiled against this obsolete overload"), EditorBrowsable(EditorBrowsableState.Never)] |
| 191 | + public static LoggerConfiguration File( |
| 192 | + this LoggerSinkConfiguration sinkConfiguration, |
| 193 | + ITextFormatter formatter, |
| 194 | + string path, |
| 195 | + LogEventLevel restrictedToMinimumLevel, |
| 196 | + long? fileSizeLimitBytes, |
| 197 | + LoggingLevelSwitch levelSwitch, |
| 198 | + bool buffered, |
| 199 | + bool shared, |
| 200 | + TimeSpan? flushToDiskInterval, |
| 201 | + RollingInterval rollingInterval, |
| 202 | + bool rollOnFileSizeLimit, |
| 203 | + int? retainedFileCountLimit, |
| 204 | + Encoding encoding) |
| 205 | + { |
| 206 | + return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch, buffered, |
| 207 | + shared, flushToDiskInterval, rollingInterval, rollOnFileSizeLimit, retainedFileCountLimit, encoding, null); |
116 | 208 | }
|
117 | 209 |
|
118 | 210 | /// <summary>
|
@@ -142,7 +234,6 @@ public static LoggerConfiguration File(
|
142 | 234 | /// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param>
|
143 | 235 | /// <param name="hooks">Optionally enables hooking into log file lifecycle events.</param>
|
144 | 236 | /// <returns>Configuration object allowing method chaining.</returns>
|
145 |
| - /// <remarks>The file will be written using the UTF-8 character set.</remarks> |
146 | 237 | public static LoggerConfiguration File(
|
147 | 238 | this LoggerSinkConfiguration sinkConfiguration,
|
148 | 239 | string path,
|
@@ -215,6 +306,10 @@ public static LoggerConfiguration File(
|
215 | 306 | Encoding encoding = null,
|
216 | 307 | FileLifecycleHooks hooks = null)
|
217 | 308 | {
|
| 309 | + if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); |
| 310 | + if (formatter == null) throw new ArgumentNullException(nameof(formatter)); |
| 311 | + if (path == null) throw new ArgumentNullException(nameof(path)); |
| 312 | + |
218 | 313 | return ConfigureFile(sinkConfiguration.Sink, formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch,
|
219 | 314 | buffered, false, shared, flushToDiskInterval, encoding, rollingInterval, rollOnFileSizeLimit,
|
220 | 315 | retainedFileCountLimit, hooks);
|
@@ -243,80 +338,71 @@ public static LoggerConfiguration File(
|
243 | 338 | IFormatProvider formatProvider,
|
244 | 339 | LoggingLevelSwitch levelSwitch)
|
245 | 340 | {
|
246 |
| - if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); |
247 |
| - if (path == null) throw new ArgumentNullException(nameof(path)); |
248 |
| - if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); |
249 |
| - |
250 |
| - var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); |
251 |
| - return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, levelSwitch, null); |
| 341 | + return File(sinkConfiguration, path, restrictedToMinimumLevel, outputTemplate, formatProvider, levelSwitch, null, null); |
252 | 342 | }
|
253 | 343 |
|
254 | 344 | /// <summary>
|
255 | 345 | /// Write log events to the specified file.
|
256 | 346 | /// </summary>
|
257 | 347 | /// <param name="sinkConfiguration">Logger sink configuration.</param>
|
| 348 | + /// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into |
| 349 | + /// text for the file. If control of regular text formatting is required, use the other |
| 350 | + /// overload of <see cref="File(LoggerAuditSinkConfiguration, string, LogEventLevel, string, IFormatProvider, LoggingLevelSwitch)"/> |
| 351 | + /// and specify the outputTemplate parameter instead. |
| 352 | + /// </param> |
258 | 353 | /// <param name="path">Path to the file.</param>
|
259 | 354 | /// <param name="restrictedToMinimumLevel">The minimum level for
|
260 | 355 | /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
|
261 | 356 | /// <param name="levelSwitch">A switch allowing the pass-through minimum level
|
262 | 357 | /// to be changed at runtime.</param>
|
263 |
| - /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> |
264 |
| - /// <param name="outputTemplate">A message template describing the format used to write to the sink. |
265 |
| - /// the default is "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}".</param> |
266 |
| - /// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param> |
267 |
| - /// <param name="hooks">Optionally enables hooking into log file lifecycle events.</param> |
268 | 358 | /// <returns>Configuration object allowing method chaining.</returns>
|
| 359 | + /// <remarks>The file will be written using the UTF-8 character set.</remarks> |
| 360 | + [Obsolete("New code should not be compiled against this obsolete overload"), EditorBrowsable(EditorBrowsableState.Never)] |
269 | 361 | public static LoggerConfiguration File(
|
270 | 362 | this LoggerAuditSinkConfiguration sinkConfiguration,
|
| 363 | + ITextFormatter formatter, |
271 | 364 | string path,
|
272 |
| - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, |
273 |
| - string outputTemplate = DefaultOutputTemplate, |
274 |
| - IFormatProvider formatProvider = null, |
275 |
| - LoggingLevelSwitch levelSwitch = null, |
276 |
| - Encoding encoding = null, |
277 |
| - FileLifecycleHooks hooks = null) |
| 365 | + LogEventLevel restrictedToMinimumLevel, |
| 366 | + LoggingLevelSwitch levelSwitch) |
278 | 367 | {
|
279 |
| - if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); |
280 |
| - if (path == null) throw new ArgumentNullException(nameof(path)); |
281 |
| - if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); |
282 |
| - |
283 |
| - var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); |
284 |
| - return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, levelSwitch, encoding, hooks); |
| 368 | + return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, levelSwitch, null, null); |
285 | 369 | }
|
286 |
| - |
| 370 | + |
287 | 371 | /// <summary>
|
288 |
| - /// Write log events to the specified file. |
| 372 | + /// Write audit log events to the specified file. |
289 | 373 | /// </summary>
|
290 | 374 | /// <param name="sinkConfiguration">Logger sink configuration.</param>
|
291 |
| - /// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into |
292 |
| - /// text for the file. If control of regular text formatting is required, use the other |
293 |
| - /// overload of <see cref="File(LoggerAuditSinkConfiguration, string, LogEventLevel, string, IFormatProvider, LoggingLevelSwitch)"/> |
294 |
| - /// and specify the outputTemplate parameter instead. |
295 |
| - /// </param> |
296 | 375 | /// <param name="path">Path to the file.</param>
|
297 | 376 | /// <param name="restrictedToMinimumLevel">The minimum level for
|
298 | 377 | /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
|
299 | 378 | /// <param name="levelSwitch">A switch allowing the pass-through minimum level
|
300 | 379 | /// to be changed at runtime.</param>
|
| 380 | + /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> |
| 381 | + /// <param name="outputTemplate">A message template describing the format used to write to the sink. |
| 382 | + /// the default is "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}".</param> |
| 383 | + /// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param> |
| 384 | + /// <param name="hooks">Optionally enables hooking into log file lifecycle events.</param> |
301 | 385 | /// <returns>Configuration object allowing method chaining.</returns>
|
302 |
| - /// <remarks>The file will be written using the UTF-8 character set.</remarks> |
303 |
| - [Obsolete("New code should not be compiled against this obsolete overload"), EditorBrowsable(EditorBrowsableState.Never)] |
304 | 386 | public static LoggerConfiguration File(
|
305 | 387 | this LoggerAuditSinkConfiguration sinkConfiguration,
|
306 |
| - ITextFormatter formatter, |
307 | 388 | string path,
|
308 |
| - LogEventLevel restrictedToMinimumLevel, |
309 |
| - LoggingLevelSwitch levelSwitch) |
| 389 | + LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, |
| 390 | + string outputTemplate = DefaultOutputTemplate, |
| 391 | + IFormatProvider formatProvider = null, |
| 392 | + LoggingLevelSwitch levelSwitch = null, |
| 393 | + Encoding encoding = null, |
| 394 | + FileLifecycleHooks hooks = null) |
310 | 395 | {
|
311 | 396 | if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
|
312 |
| - if (formatter == null) throw new ArgumentNullException(nameof(formatter)); |
313 | 397 | if (path == null) throw new ArgumentNullException(nameof(path));
|
| 398 | + if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); |
314 | 399 |
|
315 |
| - return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, levelSwitch, null); |
| 400 | + var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); |
| 401 | + return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, levelSwitch, encoding, hooks); |
316 | 402 | }
|
317 | 403 |
|
318 | 404 | /// <summary>
|
319 |
| - /// Write log events to the specified file. |
| 405 | + /// Write audit log events to the specified file. |
320 | 406 | /// </summary>
|
321 | 407 | /// <param name="sinkConfiguration">Logger sink configuration.</param>
|
322 | 408 | /// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into
|
|
0 commit comments