|  | 
| 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; | 
| @@ -102,6 +103,61 @@ public Log4NetTextFormatter(Action<Log4NetTextFormatterOptionsBuilder>? configur | 
| 102 | 103 |         _usesLog4JCompatibility = ReferenceEquals(Log4NetTextFormatterOptionsBuilder.Log4JXmlNamespace, _options.XmlNamespace); | 
| 103 | 104 |     } | 
| 104 | 105 | 
 | 
|  | 106 | +    /// <summary> | 
|  | 107 | +    /// A highly improbable value to be used as the null text. | 
|  | 108 | +    /// </summary> | 
|  | 109 | +    private const string NullTextDefaultMarker = "$Serilog.Formatting.Log4Net.Log4NetTextFormatter.nullText$"; | 
|  | 110 | + | 
|  | 111 | +    /// <summary> | 
|  | 112 | +    /// Do not use this constructor. It is only available for the <a href="https://github.com/serilog/serilog-settings-configuration">Serilog.Settings.Configuration</a> integration. | 
|  | 113 | +    /// The property filter, the message formatter and the exception formatter can only be configured through | 
|  | 114 | +    /// the <see cref="Log4NetTextFormatter(Action<Log4NetTextFormatterOptionsBuilder>)"/> constructor. | 
|  | 115 | +    /// </summary> | 
|  | 116 | +    /// <remarks> | 
|  | 117 | +    /// Binary compatibility across versions is not guaranteed. New optional parameters will be added in order to match new options. | 
|  | 118 | +    /// </remarks> | 
|  | 119 | +    [Obsolete("This constructor is only for use by the Serilog.Settings.Configuration package.", error: true)] | 
|  | 120 | +    [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "Used by Serilog.Settings.Configuration through reflection.")] | 
|  | 121 | +    public Log4NetTextFormatter( | 
|  | 122 | +        string? formatProvider = null, | 
|  | 123 | +        CDataMode? cDataMode = null, | 
|  | 124 | +        string? nullText = NullTextDefaultMarker, | 
|  | 125 | +        // 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 | 
|  | 126 | +        bool noNullText = false, | 
|  | 127 | +        bool noXmlNamespace = false, | 
|  | 128 | +        LineEnding? lineEnding = null, | 
|  | 129 | +        Indentation? indentation = null, | 
|  | 130 | +        byte? indentationSize = null, | 
|  | 131 | +        bool noIndentation = false, | 
|  | 132 | +        bool log4JCompatibility = false | 
|  | 133 | +    ) : this(options => | 
|  | 134 | +        { | 
|  | 135 | +            if (formatProvider != null) | 
|  | 136 | +                options.UseFormatProvider(CultureInfo.GetCultureInfo(formatProvider)); | 
|  | 137 | +            if (cDataMode != null) | 
|  | 138 | +                options.UseCDataMode(cDataMode.Value); | 
|  | 139 | +            if (nullText != NullTextDefaultMarker) | 
|  | 140 | +                options.UseNullText(nullText); | 
|  | 141 | +            if (noNullText) | 
|  | 142 | +                options.UseNullText(null); | 
|  | 143 | +            if (noXmlNamespace) | 
|  | 144 | +                options.UseNoXmlNamespace(); | 
|  | 145 | +            if (lineEnding != null) | 
|  | 146 | +                options.UseLineEnding(lineEnding.Value); | 
|  | 147 | +            if (indentation != null && indentationSize != null) | 
|  | 148 | +                options.UseIndentationSettings(new IndentationSettings(indentation.Value, indentationSize.Value)); | 
|  | 149 | +            else if (indentation != null) | 
|  | 150 | +                options.UseIndentationSettings(new IndentationSettings(indentation.Value, Log4NetTextFormatterOptionsBuilder.DefaultIndentationSize)); | 
|  | 151 | +            else if (indentationSize != null) | 
|  | 152 | +                options.UseIndentationSettings(new IndentationSettings(Log4NetTextFormatterOptionsBuilder.DefaultIndentation, indentationSize.Value)); | 
|  | 153 | +            if (noIndentation) | 
|  | 154 | +                options.UseNoIndentation(); | 
|  | 155 | +            if (log4JCompatibility) | 
|  | 156 | +                options.UseLog4JCompatibility(); | 
|  | 157 | +        }) | 
|  | 158 | +    { | 
|  | 159 | +    } | 
|  | 160 | + | 
| 105 | 161 |     /// <summary> | 
| 106 | 162 |     /// Format the log event as log4net or log4j compatible XML format into the output. | 
| 107 | 163 |     /// </summary> | 
|  | 
0 commit comments