Skip to content

Commit 131368d

Browse files
committed
Update to C# 10 and use file-scoped namespaces
1 parent 43d791b commit 131368d

7 files changed

+486
-492
lines changed

src/CDataMode.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
namespace Serilog.Formatting.Log4Net
1+
namespace Serilog.Formatting.Log4Net;
2+
3+
/// <summary>
4+
/// Controls how <see cref="Log4NetTextFormatter"/> writes <c>message</c> and <c>exception</c> XML elements.
5+
/// </summary>
6+
public enum CDataMode
27
{
38
/// <summary>
4-
/// Controls how <see cref="Log4NetTextFormatter"/> writes <c>message</c> and <c>exception</c> XML elements.
9+
/// The XML element content is always written as a CDATA section.
510
/// </summary>
6-
public enum CDataMode
7-
{
8-
/// <summary>
9-
/// The XML element content is always written as a CDATA section.
10-
/// </summary>
11-
Always,
12-
/// <summary>
13-
/// The XML element content is never written as a CDATA section. I.e. the characters '&amp;', '&lt;' and '&gt;' are escaped.
14-
/// </summary>
15-
Never,
16-
/// <summary>
17-
/// The XML element content is written as CDATA section if its content contains the '&amp;', '&lt;' or '&gt;' character.
18-
/// </summary>
19-
IfNeeded,
20-
}
21-
}
11+
Always,
12+
/// <summary>
13+
/// The XML element content is never written as a CDATA section. I.e. the characters '&amp;', '&lt;' and '&gt;' are escaped.
14+
/// </summary>
15+
Never,
16+
/// <summary>
17+
/// The XML element content is written as CDATA section if its content contains the '&amp;', '&lt;' or '&gt;' character.
18+
/// </summary>
19+
IfNeeded,
20+
}

src/Indentation.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
namespace Serilog.Formatting.Log4Net
1+
namespace Serilog.Formatting.Log4Net;
2+
3+
/// <summary>
4+
/// Possible values for XML elements indentation.
5+
/// </summary>
6+
public enum Indentation
27
{
38
/// <summary>
4-
/// Possible values for XML elements indentation.
9+
/// Indent with the space character, i.e. unicode U+0020.
510
/// </summary>
6-
public enum Indentation
7-
{
8-
/// <summary>
9-
/// Indent with the space character, i.e. unicode U+0020.
10-
/// </summary>
11-
Space,
12-
/// <summary>
13-
/// Indent with the tabulation character, i.e. unicode U+0009.
14-
/// </summary>
15-
Tab,
16-
}
11+
Space,
12+
/// <summary>
13+
/// Indent with the tabulation character, i.e. unicode U+0009.
14+
/// </summary>
15+
Tab,
1716
}

src/IndentationSettings.cs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
using System;
22

3-
namespace Serilog.Formatting.Log4Net
3+
namespace Serilog.Formatting.Log4Net;
4+
5+
/// <summary>
6+
/// Defines how XML elements are indented.
7+
/// </summary>
8+
public class IndentationSettings
49
{
10+
private readonly string _indentationString;
11+
512
/// <summary>
6-
/// Defines how XML elements are indented.
13+
/// Initialize a new instance of the <see cref="IndentationSettings"/> class.
714
/// </summary>
8-
public class IndentationSettings
15+
/// <param name="indentation">The <see cref="Log4Net.Indentation"/> character to use for indenting XML elements.</param>
16+
/// <param name="size">The number of times the <see cref="Indentation"/> character is repeated.</param>
17+
/// <exception cref="ArgumentOutOfRangeException">If the <paramref name="size"/> is zero or if the <paramref name="indentation"/> is an invalid value for the enum type <see cref="Indentation"/>.</exception>
18+
public IndentationSettings(Indentation indentation, byte size)
919
{
10-
private readonly string _indentationString;
11-
12-
/// <summary>
13-
/// Initialize a new instance of the <see cref="IndentationSettings"/> class.
14-
/// </summary>
15-
/// <param name="indentation">The <see cref="Log4Net.Indentation"/> character to use for indenting XML elements.</param>
16-
/// <param name="size">The number of times the <see cref="Indentation"/> character is repeated.</param>
17-
/// <exception cref="ArgumentOutOfRangeException">If the <paramref name="size"/> is zero or if the <paramref name="indentation"/> is an invalid value for the enum type <see cref="Indentation"/>.</exception>
18-
public IndentationSettings(Indentation indentation, byte size)
20+
if (size == 0)
1921
{
20-
if (size == 0)
21-
{
22-
throw new ArgumentOutOfRangeException(nameof(size), size, $"The value of argument '{nameof(size)}' must be greater than 0.");
23-
}
24-
_indentationString = indentation switch
25-
{
26-
Indentation.Space => new string(c: ' ', size),
27-
Indentation.Tab => new string(c: '\t', size),
28-
_ => throw new ArgumentOutOfRangeException(nameof(indentation), indentation, $"The value of argument '{nameof(indentation)}' ({indentation}) is invalid for enum type '{nameof(Indentation)}'.")
29-
};
22+
throw new ArgumentOutOfRangeException(nameof(size), size, $"The value of argument '{nameof(size)}' must be greater than 0.");
3023
}
31-
32-
/// <summary>
33-
/// Returns a string representation of the indentation settings.
34-
/// </summary>
35-
public override string ToString() => _indentationString;
24+
_indentationString = indentation switch
25+
{
26+
Indentation.Space => new string(c: ' ', size),
27+
Indentation.Tab => new string(c: '\t', size),
28+
_ => throw new ArgumentOutOfRangeException(nameof(indentation), indentation, $"The value of argument '{nameof(indentation)}' ({indentation}) is invalid for enum type '{nameof(Indentation)}'.")
29+
};
3630
}
31+
32+
/// <summary>
33+
/// Returns a string representation of the indentation settings.
34+
/// </summary>
35+
public override string ToString() => _indentationString;
3736
}

src/LineEnding.cs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
11
using System;
22

3-
namespace Serilog.Formatting.Log4Net
3+
namespace Serilog.Formatting.Log4Net;
4+
5+
/// <summary>
6+
/// Possible XML line endings.
7+
/// <para>Both <see cref="CarriageReturn"/> and <see cref="LineFeed"/> can be combined, i.e. <c>LineEnding.CarriageReturn | LineEnding.LineFeed</c> in order to produce the CR+LF characters.</para>
8+
/// <para>See also [End-of-Line Handling](https://www.w3.org/TR/xml/#sec-line-ends) in the XML specification.</para>
9+
/// </summary>
10+
[Flags]
11+
public enum LineEnding
412
{
513
/// <summary>
6-
/// Possible XML line endings.
7-
/// <para>Both <see cref="CarriageReturn"/> and <see cref="LineFeed"/> can be combined, i.e. <c>LineEnding.CarriageReturn | LineEnding.LineFeed</c> in order to produce the CR+LF characters.</para>
8-
/// <para>See also [End-of-Line Handling](https://www.w3.org/TR/xml/#sec-line-ends) in the XML specification.</para>
14+
/// No line ending.
915
/// </summary>
10-
[Flags]
11-
public enum LineEnding
12-
{
13-
/// <summary>
14-
/// No line ending.
15-
/// </summary>
16-
None = 0,
17-
/// <summary>
18-
/// End lines with the line feed (LF) character, i.e. unicode U+000A.
19-
/// </summary>
20-
LineFeed = 1,
21-
/// <summary>
22-
/// End lines with the carriage return (CR) character, i.e. unicode U+000D.
23-
/// </summary>
24-
CarriageReturn = 2,
25-
}
16+
None = 0,
17+
/// <summary>
18+
/// End lines with the line feed (LF) character, i.e. unicode U+000A.
19+
/// </summary>
20+
LineFeed = 1,
21+
/// <summary>
22+
/// End lines with the carriage return (CR) character, i.e. unicode U+000D.
23+
/// </summary>
24+
CarriageReturn = 2,
25+
}
2626

27+
/// <summary>
28+
/// Extensions to the <see cref="LineEnding"/> enum type.
29+
/// </summary>
30+
internal static class LineEndingExtensions
31+
{
2732
/// <summary>
28-
/// Extensions to the <see cref="LineEnding"/> enum type.
33+
/// Returns a string representation of the specified <paramref name="lineEnding"/>.
2934
/// </summary>
30-
internal static class LineEndingExtensions
35+
/// <param name="lineEnding">The <see cref="LineEnding"/> to convert to a string.</param>
36+
/// <returns>A string representation of the <see cref="LineEnding"/>.</returns>
37+
public static string ToCharacters(this LineEnding lineEnding)
3138
{
32-
/// <summary>
33-
/// Returns a string representation of the specified <paramref name="lineEnding"/>.
34-
/// </summary>
35-
/// <param name="lineEnding">The <see cref="LineEnding"/> to convert to a string.</param>
36-
/// <returns>A string representation of the <see cref="LineEnding"/>.</returns>
37-
public static string ToCharacters(this LineEnding lineEnding)
39+
return lineEnding switch
3840
{
39-
return lineEnding switch
40-
{
41-
LineEnding.None => "",
42-
LineEnding.LineFeed => "\n",
43-
LineEnding.CarriageReturn => "\r",
44-
LineEnding.CarriageReturn | LineEnding.LineFeed => "\r\n",
45-
_ => throw new ArgumentOutOfRangeException(nameof(lineEnding), lineEnding, $"The value of argument '{nameof(lineEnding)}' ({lineEnding}) is invalid for enum type '{nameof(LineEnding)}'.")
46-
};
47-
}
41+
LineEnding.None => "",
42+
LineEnding.LineFeed => "\n",
43+
LineEnding.CarriageReturn => "\r",
44+
LineEnding.CarriageReturn | LineEnding.LineFeed => "\r\n",
45+
_ => throw new ArgumentOutOfRangeException(nameof(lineEnding), lineEnding, $"The value of argument '{nameof(lineEnding)}' ({lineEnding}) is invalid for enum type '{nameof(LineEnding)}'.")
46+
};
4847
}
4948
}

0 commit comments

Comments
 (0)