|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Diagnostics.CodeAnalysis;
|
| 4 | +using System.Globalization; |
4 | 5 | using System.IO;
|
5 | 6 | using System.Linq;
|
6 | 7 | using System.Text.RegularExpressions;
|
@@ -93,6 +94,56 @@ public Log4NetTextFormatter(Action<Log4NetTextFormatterOptionsBuilder>? configur
|
93 | 94 | _usesLog4JCompatibility = ReferenceEquals(Log4NetTextFormatterOptionsBuilder.Log4JXmlNamespace, _options.XmlNamespace);
|
94 | 95 | }
|
95 | 96 |
|
| 97 | + /// <summary> |
| 98 | + /// A highly improbable value to be used as the null text. |
| 99 | + /// </summary> |
| 100 | + private const string NullTextDefaultMarker = "$Serilog.Formatting.Log4Net.Log4NetTextFormatter.nullText$"; |
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Do not use this constructor. It is only available for the Serilog.Settings.Configuration integration. |
| 104 | + /// </summary> |
| 105 | + [Obsolete("This constructor is only for use by the Serilog.Settings.Configuration package.", error: true)] |
| 106 | + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "Used by Serilog.Settings.Configuration through reflection.")] |
| 107 | + public Log4NetTextFormatter( |
| 108 | + string? formatProvider = null, |
| 109 | + CDataMode? cDataMode = null, |
| 110 | + string? nullText = NullTextDefaultMarker, |
| 111 | + // in order to support options.UseNullText(null) on .NET < 10, see https://learn.microsoft.com/en-us/dotnet/core/compatibility/extensions/10.0/configuration-null-values-preserved |
| 112 | + bool noNullText = false, |
| 113 | + bool noXmlNamespace = false, |
| 114 | + LineEnding? lineEnding = null, |
| 115 | + Indentation? indentation = null, |
| 116 | + byte? indentationSize = null, |
| 117 | + bool noIndentation = false, |
| 118 | + bool log4JCompatibility = false |
| 119 | + ) : this(options => |
| 120 | + { |
| 121 | + if (formatProvider != null) |
| 122 | + options.UseFormatProvider(CultureInfo.GetCultureInfo(formatProvider)); |
| 123 | + if (cDataMode != null) |
| 124 | + options.UseCDataMode(cDataMode.Value); |
| 125 | + if (nullText != NullTextDefaultMarker) |
| 126 | + options.UseNullText(nullText); |
| 127 | + if (noNullText) |
| 128 | + options.UseNullText(null); |
| 129 | + if (noXmlNamespace) |
| 130 | + options.UseNoXmlNamespace(); |
| 131 | + if (lineEnding != null) |
| 132 | + options.UseLineEnding(lineEnding.Value); |
| 133 | + if (indentation != null && indentationSize != null) |
| 134 | + options.UseIndentationSettings(new IndentationSettings(indentation.Value, indentationSize.Value)); |
| 135 | + else if (indentation != null) |
| 136 | + options.UseIndentationSettings(new IndentationSettings(indentation.Value, Log4NetTextFormatterOptionsBuilder.DefaultIndentationSize)); |
| 137 | + else if (indentationSize != null) |
| 138 | + options.UseIndentationSettings(new IndentationSettings(Log4NetTextFormatterOptionsBuilder.DefaultIndentation, indentationSize.Value)); |
| 139 | + if (noIndentation) |
| 140 | + options.UseNoIndentation(); |
| 141 | + if (log4JCompatibility) |
| 142 | + options.UseLog4JCompatibility(); |
| 143 | + }) |
| 144 | + { |
| 145 | + } |
| 146 | + |
96 | 147 | /// <summary>
|
97 | 148 | /// Format the log event as log4net or log4j compatible XML format into the output.
|
98 | 149 | /// </summary>
|
|
0 commit comments