Skip to content

Commit ffc2c0f

Browse files
authored
Merge pull request #98 from rafaelsc/feature/nullableReference
Add support C# 8 nullable reference types
2 parents ddb04ae + 89af075 commit ffc2c0f

22 files changed

+194
-50
lines changed

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
version: '{build}'
22
skip_tags: true
3-
image:
4-
- Visual Studio 2019
3+
image: Visual Studio 2019
54
configuration: Release
65
test: off
76
build_script:

src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public static LoggerConfiguration Console(
5656
this LoggerSinkConfiguration sinkConfiguration,
5757
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
5858
string outputTemplate = DefaultConsoleOutputTemplate,
59-
IFormatProvider formatProvider = null,
60-
LoggingLevelSwitch levelSwitch = null,
59+
IFormatProvider? formatProvider = null,
60+
LoggingLevelSwitch? levelSwitch = null,
6161
LogEventLevel? standardErrorFromLevel = null,
62-
ConsoleTheme theme = null,
62+
ConsoleTheme? theme = null,
6363
bool applyThemeToRedirectedOutput = false,
64-
object syncRoot = null)
64+
object? syncRoot = null)
6565
{
6666
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
6767
if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate));
@@ -70,7 +70,7 @@ public static LoggerConfiguration Console(
7070
ConsoleTheme.None :
7171
theme ?? SystemConsoleThemes.Literate;
7272

73-
syncRoot = syncRoot ?? DefaultSyncRoot;
73+
syncRoot ??= DefaultSyncRoot;
7474

7575
var formatter = new OutputTemplateRenderer(appliedTheme, outputTemplate, formatProvider);
7676
return sinkConfiguration.Sink(new ConsoleSink(appliedTheme, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch);
@@ -97,14 +97,15 @@ public static LoggerConfiguration Console(
9797
this LoggerSinkConfiguration sinkConfiguration,
9898
ITextFormatter formatter,
9999
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
100-
LoggingLevelSwitch levelSwitch = null,
100+
LoggingLevelSwitch? levelSwitch = null,
101101
LogEventLevel? standardErrorFromLevel = null,
102-
object syncRoot = null)
102+
object? syncRoot = null)
103103
{
104104
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
105105
if (formatter is null) throw new ArgumentNullException(nameof(formatter));
106106

107-
syncRoot = syncRoot ?? DefaultSyncRoot;
107+
syncRoot ??= DefaultSyncRoot;
108+
108109
return sinkConfiguration.Sink(new ConsoleSink(ConsoleTheme.None, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch);
109110
}
110111
}

src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>A Serilog sink that writes log events to the console/terminal.</Description>
55
<VersionPrefix>4.0.0</VersionPrefix>
66
<Authors>Serilog Contributors</Authors>
77
<TargetFrameworks>net45;netstandard1.3;netstandard2.0;</TargetFrameworks>
8+
<LangVersion>8.0</LangVersion>
9+
<Nullable>enable</Nullable>
810
<AssemblyName>Serilog.Sinks.Console</AssemblyName>
911
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
1012
<SignAssembly>true</SignAssembly>

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ namespace Serilog.Sinks.SystemConsole.Formatting
2222
{
2323
class ThemedDisplayValueFormatter : ThemedValueFormatter
2424
{
25-
readonly IFormatProvider _formatProvider;
25+
readonly IFormatProvider? _formatProvider;
2626

27-
public ThemedDisplayValueFormatter(ConsoleTheme theme, IFormatProvider formatProvider)
27+
public ThemedDisplayValueFormatter(ConsoleTheme theme, IFormatProvider? formatProvider)
2828
: base(theme)
2929
{
3030
_formatProvider = formatProvider;
@@ -150,7 +150,7 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic
150150
return count;
151151
}
152152

153-
public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
153+
public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string? format)
154154
{
155155
var value = scalar.Value;
156156
var count = 0;

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ namespace Serilog.Sinks.SystemConsole.Formatting
2424
class ThemedJsonValueFormatter : ThemedValueFormatter
2525
{
2626
readonly ThemedDisplayValueFormatter _displayFormatter;
27-
readonly IFormatProvider _formatProvider;
27+
readonly IFormatProvider? _formatProvider;
2828

29-
public ThemedJsonValueFormatter(ConsoleTheme theme, IFormatProvider formatProvider)
29+
public ThemedJsonValueFormatter(ConsoleTheme theme, IFormatProvider? formatProvider)
3030
: base(theme)
3131
{
3232
_displayFormatter = new ThemedDisplayValueFormatter(theme, formatProvider);
@@ -154,7 +154,7 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic
154154
: ConsoleThemeStyle.Scalar;
155155

156156
using (ApplyStyle(state.Output, style, ref count))
157-
JsonValueFormatter.WriteQuotedJsonString((element.Key.Value ?? "null").ToString(), state.Output);
157+
JsonValueFormatter.WriteQuotedJsonString((element.Key.Value ?? "null").ToString() ?? "", state.Output);
158158

159159
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
160160
state.Output.Write(": ");
@@ -248,7 +248,7 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output)
248248
}
249249

250250
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
251-
JsonValueFormatter.WriteQuotedJsonString(value.ToString(), output);
251+
JsonValueFormatter.WriteQuotedJsonString(value.ToString() ?? "", output);
252252

253253
return count;
254254
}

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected StyleReset ApplyStyle(TextWriter output, ConsoleThemeStyle style, ref
3434
return _theme.Apply(output, style, ref invisibleCharacterCount);
3535
}
3636

37-
public int Format(LogEventPropertyValue value, TextWriter output, string format, bool literalTopLevel = false)
37+
public int Format(LogEventPropertyValue value, TextWriter output, string? format, bool literalTopLevel = false)
3838
{
3939
return Visit(new ThemedValueFormatterState { Output = output, Format = format, IsTopLevel = literalTopLevel }, value);
4040
}

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Serilog.Sinks.SystemConsole.Formatting
1919
struct ThemedValueFormatterState
2020
{
2121
public TextWriter Output;
22-
public string Format;
22+
public string? Format;
2323
public bool IsTopLevel;
2424

2525
public ThemedValueFormatterState Nest() => new ThemedValueFormatterState { Output = Output };

src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class EventPropertyTokenRenderer : OutputTemplateTokenRenderer
2525
{
2626
readonly ConsoleTheme _theme;
2727
readonly PropertyToken _token;
28-
readonly IFormatProvider _formatProvider;
28+
readonly IFormatProvider? _formatProvider;
2929

30-
public EventPropertyTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider formatProvider)
30+
public EventPropertyTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider? formatProvider)
3131
{
3232
_theme = theme;
3333
_token = token;
@@ -62,7 +62,7 @@ public override void Render(LogEvent logEvent, TextWriter output)
6262

6363
if (_token.Alignment.HasValue)
6464
{
65-
var str = writer.ToString();
65+
var str = writer.ToString()!;
6666
Padding.Apply(output, str, _token.Alignment);
6767
}
6868
}

src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void Render(LogEvent logEvent, TextWriter output)
3838
return;
3939

4040
var lines = new StringReader(logEvent.Exception.ToString());
41-
string nextLine;
41+
string? nextLine;
4242
while ((nextLine = lines.ReadLine()) != null)
4343
{
4444
var style = nextLine.StartsWith(StackFrameLinePrefix) ? ConsoleThemeStyle.SecondaryText : ConsoleThemeStyle.Text;

src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static class LevelOutputFormat
5555
new[] { "F", "FA", "FTL", "FATL" },
5656
};
5757

58-
public static string GetLevelMoniker(LogEventLevel value, string format = null)
58+
public static string GetLevelMoniker(LogEventLevel value, string? format = null)
5959
{
6060
if (format is null || format.Length != 2 && format.Length != 3)
6161
return Casing.Format(value.ToString(), format);

0 commit comments

Comments
 (0)