|
17 | 17 | using Serilog.Core; |
18 | 18 | using Serilog.Debugging; |
19 | 19 | using Serilog.Events; |
| 20 | +using Serilog.Formatting; |
20 | 21 | using Serilog.Formatting.Display; |
| 22 | +using Serilog.Formatting.Json; |
21 | 23 | using Serilog.Sinks.File; |
22 | 24 |
|
23 | 25 | namespace Serilog |
@@ -57,8 +59,45 @@ public static LoggerConfiguration File( |
57 | 59 | bool buffered = false) |
58 | 60 | { |
59 | 61 | if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); |
| 62 | + if (path == null) throw new ArgumentNullException(nameof(path)); |
60 | 63 | if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); |
| 64 | + |
61 | 65 | var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); |
| 66 | + return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch, buffered); |
| 67 | + } |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Write log events to the specified file. |
| 71 | + /// </summary> |
| 72 | + /// <param name="sinkConfiguration">Logger sink configuration.</param> |
| 73 | + /// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into |
| 74 | + /// text for the file. If control of regular text formatting is required, use the other |
| 75 | + /// overload of <see cref="File(LoggerSinkConfiguration, string, LogEventLevel, string, IFormatProvider, long?, LoggingLevelSwitch, bool)"/> |
| 76 | + /// and specify the outputTemplate parameter instead. |
| 77 | + /// </param> |
| 78 | + /// <param name="path">Path to the file.</param> |
| 79 | + /// <param name="restrictedToMinimumLevel">The minimum level for |
| 80 | + /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> |
| 81 | + /// <param name="levelSwitch">A switch allowing the pass-through minimum level |
| 82 | + /// to be changed at runtime.</param> |
| 83 | + /// <param name="fileSizeLimitBytes">The maximum size, in bytes, to which a log file will be allowed to grow. |
| 84 | + /// For unrestricted growth, pass null. The default is 1 GB.</param> |
| 85 | + /// <param name="buffered">Indicates if flushing to the output file can be buffered or not. The default |
| 86 | + /// is false.</param> |
| 87 | + /// <returns>Configuration object allowing method chaining.</returns> |
| 88 | + /// <remarks>The file will be written using the UTF-8 character set.</remarks> |
| 89 | + public static LoggerConfiguration File( |
| 90 | + this LoggerSinkConfiguration sinkConfiguration, |
| 91 | + ITextFormatter formatter, |
| 92 | + string path, |
| 93 | + LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, |
| 94 | + long? fileSizeLimitBytes = DefaultFileSizeLimitBytes, |
| 95 | + LoggingLevelSwitch levelSwitch = null, |
| 96 | + bool buffered = false) |
| 97 | + { |
| 98 | + if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); |
| 99 | + if (formatter == null) throw new ArgumentNullException(nameof(formatter)); |
| 100 | + if (path == null) throw new ArgumentNullException(nameof(path)); |
62 | 101 |
|
63 | 102 | FileSink sink; |
64 | 103 | try |
|
0 commit comments