Skip to content

Commit 0d91aae

Browse files
authored
Merge pull request #3 from nblumhardt/dev
Accept an ITextFormatter in an overload of WriteTo.Console()
2 parents 80ce72c + 1d5c65e commit 0d91aae

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Serilog.Configuration;
33
using Serilog.Core;
44
using Serilog.Events;
5+
using Serilog.Formatting;
56
using Serilog.Formatting.Display;
67
using Serilog.Sinks.SystemConsole;
78

@@ -36,6 +37,28 @@ public static LoggerConfiguration Console(
3637
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
3738
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
3839
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
40+
return Console(sinkConfiguration, formatter, restrictedToMinimumLevel, levelSwitch);
41+
}
42+
43+
/// <summary>
44+
/// Writes log events to <see cref="System.Console"/>.
45+
/// </summary>
46+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
47+
/// <param name="formatter">Controls the rendering of log events into text, for example to log JSON. To
48+
/// control plain text formatting, use the overload that accepts an output template.</param>
49+
/// <param name="restrictedToMinimumLevel">The minimum level for
50+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
51+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
52+
/// to be changed at runtime.</param>
53+
/// <returns>Configuration object allowing method chaining.</returns>
54+
public static LoggerConfiguration Console(
55+
this LoggerSinkConfiguration sinkConfiguration,
56+
ITextFormatter formatter,
57+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
58+
LoggingLevelSwitch levelSwitch = null)
59+
{
60+
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
61+
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
3962
return sinkConfiguration.Sink(new ConsoleSink(formatter), restrictedToMinimumLevel, levelSwitch);
4063
}
4164
}

0 commit comments

Comments
 (0)