Skip to content

Commit

Permalink
Some field to protected
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyte committed Jul 17, 2023
1 parent 274c913 commit edada7f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Serilog.Sinks.Grafana.Loki/LokiJsonTextFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ namespace Serilog.Sinks.Grafana.Loki;
Justification = "Reviewed")]
public class LokiJsonTextFormatter : ITextFormatter
{
private static readonly string[] ReservedKeywords = { "Message", "MessageTemplate", "Renderings", "Exception" };
/// <summary>
/// Renaming strategy for properties names equal to reserved keywords.
/// </summary>
protected readonly IReservedPropertyRenamingStrategy RenamingStrategy;
/// <summary>
/// <see cref="Serilog.Formatting.Json.JsonFormatter"/>.
/// </summary>
protected readonly JsonValueFormatter ValueFormatter;

private readonly IReservedPropertyRenamingStrategy _renamingStrategy;
private readonly JsonValueFormatter _valueFormatter;
private static readonly string[] ReservedKeywords = { "Message", "MessageTemplate", "Renderings", "Exception" };

/// <summary>
/// Initializes a new instance of the <see cref="LokiJsonTextFormatter"/> class.
Expand All @@ -49,8 +55,8 @@ public LokiJsonTextFormatter()
/// </param>
public LokiJsonTextFormatter(IReservedPropertyRenamingStrategy renamingStrategy)
{
_renamingStrategy = renamingStrategy;
_valueFormatter = new JsonValueFormatter("$type");
RenamingStrategy = renamingStrategy;
ValueFormatter = new JsonValueFormatter("$type");
}

/// <summary>
Expand Down Expand Up @@ -116,7 +122,7 @@ public virtual void Format(LogEvent logEvent, TextWriter output)
output.Write(',');
JsonValueFormatter.WriteQuotedJsonString(name, output);
output.Write(':');
_valueFormatter.Format(value, output);
ValueFormatter.Format(value, output);
}

output.Write('}');
Expand All @@ -130,7 +136,7 @@ public virtual void Format(LogEvent logEvent, TextWriter output)
/// Name of property to sanitize
/// </param>
protected virtual string GetSanitizedPropertyName(string propertyName) =>
ReservedKeywords.Contains(propertyName) ? _renamingStrategy.Rename(propertyName) : propertyName;
ReservedKeywords.Contains(propertyName) ? RenamingStrategy.Rename(propertyName) : propertyName;

/// <summary>
/// Used to serialize exceptions, can be overridden when inheriting to change the format.
Expand Down

0 comments on commit edada7f

Please sign in to comment.