LogEventPropertyValueVisitor
Namespace:
Serilog
We found 10 examples in language CSharp for this search.
You will see 51 fragments of code.
Other methods
Other methods
Project:learning
File:ThemedValueFormatter.cs
Examples:3
protected StyleReset ApplyStyle(TextWriter output, ConsoleThemeStyle style, ref int invisibleCharacterCount)
{
return _theme.Apply(output, style, ref invisibleCharacterCount);
}
public int Format(LogEventPropertyValue value, TextWriter output, string format, bool literalTopLevel = false)
{
return Visit(new ThemedValueFormatterState { Output = output, Format = format, IsTopLevel = literalTopLevel }, value);
}
public abstract ThemedValueFormatter SwitchTheme(ConsoleTheme theme);
Project:xrm-framework
File:ThemedValueFormatter.cs
Examples:3
protected StyleReset ApplyStyle(TextWriter output, ConsoleThemeStyle style, ref int invisibleCharacterCount)
{
return _theme.Apply(output, style, ref invisibleCharacterCount);
}
public int Format(LogEventPropertyValue value, TextWriter output, string format, bool literalTopLevel = false)
{
return Visit(new ThemedValueFormatterState { Output = output, Format = format, IsTopLevel = literalTopLevel }, value);
}
public abstract ThemedValueFormatter SwitchTheme(ConsoleTheme theme);
Project:VisioCleanup
File:ThemedValueFormatter.cs
Examples:4
internal void Format(LogEventPropertyValue value, RichTextBox output, string formatString, bool literalTopLevel = false)
{
var themedValueFormatterState = new ThemedValueFormatterState { Output = output, Format = formatString, IsTopLevel = literalTopLevel };
this.Visit(themedValueFormatterState, value);
}
protected StyleReset ApplyStyle(RichTextBox output, RichTextThemeStyle style) => this.theme.Apply(output, style);
protected void OutputText(RichTextBox output, string text, RichTextThemeStyle richTextThemeStyle)
{
using (this.ApplyStyle(output, richTextThemeStyle))
{
output.AppendText(text);
}
}
protected int VisitDictionaryValueInternal(ThemedValueFormatterState state, DictionaryValue dictionary, VisitDictionaryValueLine lineFormatting)
{
var count = 0;
this.OutputText(state.Output, "{", RichTextThemeStyle.TertiaryText);
var delim = string.Empty;
foreach (var pair in dictionary.Elements)
{
lineFormatting(pair, ref delim, ref count);
}
this.OutputText(state.Output, "}", RichTextThemeStyle.TertiaryText);
return count;
}
Project:Serilog-Unity
File:LogEventPropertyValueVisitor.cs
Examples:6
/// <summary>
/// Visit the root node type. This method delegates to
/// a concrete Visit*Value() method appropriate for the value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
/// <exception cref="ArgumentNullException">When <paramref name="value"/> is <code>null</code></exception>
protected virtual TResult Visit(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
if (value is ScalarValue sv)
return VisitScalarValue(state, sv);
if (value is SequenceValue seqv)
return VisitSequenceValue(state, seqv);
if (value is StructureValue strv)
return VisitStructureValue(state, strv);
if (value is DictionaryValue dictv)
return VisitDictionaryValue(state, dictv);
return VisitUnsupportedValue(state, value);
}
/// <summary>
/// Visit a <see cref="ScalarValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="scalar">The value to visit.</param>
/// <returns>The result of visiting <paramref name="scalar"/>.</returns>
protected abstract TResult VisitScalarValue(TState state, ScalarValue scalar);
/// <summary>
/// Visit a <see cref="SequenceValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="sequence">The value to visit.</param>
/// <returns>The result of visiting <paramref name="sequence"/>.</returns>
protected abstract TResult VisitSequenceValue(TState state, SequenceValue sequence);
/// <summary>
/// Visit a <see cref="StructureValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="structure">The value to visit.</param>
/// <returns>The result of visiting <paramref name="structure"/>.</returns>
protected abstract TResult VisitStructureValue(TState state, StructureValue structure);
/// <summary>
/// Visit a <see cref="DictionaryValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="dictionary">The value to visit.</param>
/// <returns>The result of visiting <paramref name="dictionary"/>.</returns>
protected abstract TResult VisitDictionaryValue(TState state, DictionaryValue dictionary);
/// <summary>
/// Visit a value of an unsupported type. Always throws <see cref="NotSupportedException"/>, when is not overridden.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
/// <exception cref="ArgumentNullException">When <paramref name="value"/> is <code>null</code></exception>
/// <exception cref="NotSupportedException">Always</exception>
// ReSharper disable once UnusedParameter.Global
protected virtual TResult VisitUnsupportedValue(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
throw new NotSupportedException($"The value {value} is not of a type supported by this visitor.");
}
Project:Serilog.Logfmt
File:LogfmtValueFormatter.cs
Examples:6
public void Format(string key, LogEventPropertyValue value, TextWriter output)
{
_keys.Add(key);
Visit(output, value);
output.Write(" ");
_keys.RemoveAt(_keys.Count - 1);
}
protected override bool VisitDictionaryValue(TextWriter state, DictionaryValue dictionary)
{
return false;
}
protected override bool VisitScalarValue(TextWriter state, ScalarValue scalar)
{
var keyName = GetFullKeyName();
var svalue = scalar.Value?.ToString() ?? "\"\"";
state.Write("{0}=", keyName);
var needQuotes = svalue.Contains(" ");
if (needQuotes)
{
switch (_options.DoubleQuotesAction)
{
case DoubleQuotesAction.ConvertToSingle:
svalue = svalue.Replace('"', '\'');
break;
case DoubleQuotesAction.Remove:
svalue = svalue.Replace(@"""", "");
break;
case DoubleQuotesAction.Escape:
svalue = svalue.Replace(@"""", @"\""");
break;
default: break;
}
}
state.Write("{1}{0}{1}", svalue, needQuotes ? "\"" : "");
return true;
}
private string GetFullKeyName()
{
var sb = new StringBuilder();
for (var idx = 0; idx < _keys.Count; idx++)
{
var key = _keys[idx];
sb.Append(key);
if (idx < _keys.Count -1 && _keys[idx + 1][0] != '[') // Keys that are indexes of Sequence start with [ and in this case we don't want to use the separator
{
sb.Append(_options.ComplexPropertySeparator);
}
}
return sb.ToString();
}
protected override bool VisitSequenceValue(TextWriter state, SequenceValue sequence)
{
var idx = 0;
foreach (var value in sequence.Elements)
{
Format($"[{idx}]", value, state);
idx++;
}
return false;
}
protected override bool VisitStructureValue(TextWriter state, StructureValue structure)
{
foreach (var prop in structure.Properties)
{
var name = _options.NormalizeCase ? prop.Name.ToLowerInvariant() : prop.Name;
Format(name, prop.Value, state);
}
return true;
}
Project:seq-extensions-logging
File:LogEventPropertyValueVisitor.cs
Examples:6
/// <summary>
/// Visit the root node type. This method delegates to
/// a concrete Visit*Value() method appropriate for the value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
// ReSharper disable once VirtualMemberNeverOverriden.Global
protected virtual TResult Visit(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
var sv = value as ScalarValue;
if (sv != null)
return VisitScalarValue(state, sv);
var seqv = value as SequenceValue;
if (seqv != null)
return VisitSequenceValue(state, seqv);
var strv = value as StructureValue;
if (strv != null)
return VisitStructureValue(state, strv);
var dictv = value as DictionaryValue;
if (dictv != null)
return VisitDictionaryValue(state, dictv);
return VisitUnsupportedValue(state, value);
}
/// <summary>
/// Visit a <see cref="ScalarValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="scalar">The value to visit.</param>
/// <returns>The result of visiting <paramref name="scalar"/>.</returns>
protected abstract TResult VisitScalarValue(TState state, ScalarValue scalar);
/// <summary>
/// Visit a <see cref="SequenceValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="sequence">The value to visit.</param>
/// <returns>The result of visiting <paramref name="sequence"/>.</returns>
protected abstract TResult VisitSequenceValue(TState state, SequenceValue sequence);
/// <summary>
/// Visit a <see cref="StructureValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="structure">The value to visit.</param>
/// <returns>The result of visiting <paramref name="structure"/>.</returns>
protected abstract TResult VisitStructureValue(TState state, StructureValue structure);
/// <summary>
/// Visit a <see cref="DictionaryValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="dictionary">The value to visit.</param>
/// <returns>The result of visiting <paramref name="dictionary"/>.</returns>
protected abstract TResult VisitDictionaryValue(TState state, DictionaryValue dictionary);
/// <summary>
/// Visit a value of an unsupported type.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
// ReSharper disable once UnusedParameter.Global
// ReSharper disable once VirtualMemberNeverOverriden.Global
protected virtual TResult VisitUnsupportedValue(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
throw new NotSupportedException($"The value {value} is not of a type supported by this visitor.");
}
Project:Serilog-Unity
File:LogEventPropertyValueRewriter.cs
Examples:5
/// <summary>
/// Visit a <see cref="ScalarValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="scalar">The value to visit.</param>
/// <returns>The result of visiting <paramref name="scalar"/>.</returns>
/// <exception cref="ArgumentNullException">When <paramref name="scalar"/> is <code>null</code></exception>
protected override LogEventPropertyValue VisitScalarValue(TState state, ScalarValue scalar)
{
if (scalar == null) throw new ArgumentNullException(nameof(scalar));
return scalar;
}
/// <summary>
/// Visit a <see cref="SequenceValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="sequence">The value to visit.</param>
/// <returns>The result of visiting <paramref name="sequence"/>.</returns>
/// <exception cref="ArgumentNullException">When <paramref name="sequence"/> is <code>null</code></exception>
protected override LogEventPropertyValue VisitSequenceValue(TState state, SequenceValue sequence)
{
if (sequence == null) throw new ArgumentNullException(nameof(sequence));
for (var i = 0; i < sequence.Elements.Count; ++i)
{
var original = sequence.Elements[i];
if (!ReferenceEquals(original, Visit(state, original)))
{
var contents = new LogEventPropertyValue[sequence.Elements.Count];
// There's no need to visit any earlier elements: they all evaluated to
// a reference equal with the original so just fill in the array up until `i`.
for (var j = 0; j < i; ++j)
{
contents[j] = sequence.Elements[j];
}
for (var k = i; k < contents.Length; ++k)
{
contents[k] = Visit(state, sequence.Elements[k]);
}
return new SequenceValue(contents);
}
}
return sequence;
}
/// <summary>
/// Visit a <see cref="StructureValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="structure">The value to visit.</param>
/// <returns>The result of visiting <paramref name="structure"/>.</returns>
/// <exception cref="ArgumentNullException">When <paramref name="structure"/> is <code>null</code></exception>
protected override LogEventPropertyValue VisitStructureValue(TState state, StructureValue structure)
{
if (structure == null) throw new ArgumentNullException(nameof(structure));
for (var i = 0; i < structure.Properties.Count; ++i)
{
var original = structure.Properties[i];
if (!ReferenceEquals(original.Value, Visit(state, original.Value)))
{
var properties = new LogEventProperty[structure.Properties.Count];
// There's no need to visit any earlier elements: they all evaluated to
// a reference equal with the original so just fill in the array up until `i`.
for (var j = 0; j < i; ++j)
{
properties[j] = structure.Properties[j];
}
for (var k = i; k < properties.Length; ++k)
{
var property = structure.Properties[k];
properties[k] = new LogEventProperty(property.Name, Visit(state, property.Value));
}
return new StructureValue(properties, structure.TypeTag);
}
}
return structure;
}
/// <summary>
/// Visit a <see cref="DictionaryValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="dictionary">The value to visit.</param>
/// <returns>The result of visiting <paramref name="dictionary"/>.</returns>
/// <exception cref="ArgumentNullException">When <paramref name="dictionary"/> is <code>null</code></exception>
protected override LogEventPropertyValue VisitDictionaryValue(TState state, DictionaryValue dictionary)
{
if (dictionary == null) throw new ArgumentNullException(nameof(dictionary));
foreach (var original in dictionary.Elements)
{
if (!ReferenceEquals(original.Value, Visit(state, original.Value)))
{
var elements = new Dictionary<ScalarValue, LogEventPropertyValue>(dictionary.Elements.Count);
foreach (var element in dictionary.Elements)
{
elements[element.Key] = Visit(state, element.Value);
}
return new DictionaryValue(elements);
}
}
return dictionary;
}
/// <summary>
/// Visit a value of an unsupported type. Returns the value unchanged.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
// ReSharper disable once UnusedParameter.Global
// ReSharper disable once VirtualMemberNeverOverriden.Global
protected override LogEventPropertyValue VisitUnsupportedValue(TState state, LogEventPropertyValue value)
{
return value;
}
Project:examplebugrepoforserilogbrowserconsole
File:LogEventPropertyValueVisitor.cs
Examples:6
/// <summary>
/// Visit the root node type. This method delegates to
/// a concrete Visit*Value() method appropriate for the value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
protected virtual TResult Visit(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
if (value is ScalarValue sv)
return VisitScalarValue(state, sv);
if (value is SequenceValue seqv)
return VisitSequenceValue(state, seqv);
if (value is StructureValue strv)
return VisitStructureValue(state, strv);
if (value is DictionaryValue dictv)
return VisitDictionaryValue(state, dictv);
return VisitUnsupportedValue(state, value);
}
/// <summary>
/// Visit a <see cref="ScalarValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="scalar">The value to visit.</param>
/// <returns>The result of visiting <paramref name="scalar"/>.</returns>
protected abstract TResult VisitScalarValue(TState state, ScalarValue scalar);
/// <summary>
/// Visit a <see cref="SequenceValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="sequence">The value to visit.</param>
/// <returns>The result of visiting <paramref name="sequence"/>.</returns>
protected abstract TResult VisitSequenceValue(TState state, SequenceValue sequence);
/// <summary>
/// Visit a <see cref="StructureValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="structure">The value to visit.</param>
/// <returns>The result of visiting <paramref name="structure"/>.</returns>
protected abstract TResult VisitStructureValue(TState state, StructureValue structure);
/// <summary>
/// Visit a <see cref="DictionaryValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="dictionary">The value to visit.</param>
/// <returns>The result of visiting <paramref name="dictionary"/>.</returns>
protected abstract TResult VisitDictionaryValue(TState state, DictionaryValue dictionary);
/// <summary>
/// Visit a value of an unsupported type.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
// ReSharper disable once UnusedParameter.Global
protected virtual TResult VisitUnsupportedValue(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
throw new NotSupportedException($"The value {value} is not of a type supported by this visitor.");
}
Project:SkynetClient
File:LogEventPropertyValueVisitor.cs
Examples:6
/// <summary>
/// Visit the root node type. This method delegates to
/// a concrete Visit*Value() method appropriate for the value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
protected virtual TResult Visit(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
var sv = value as ScalarValue;
if (sv != null)
return VisitScalarValue(state, sv);
var seqv = value as SequenceValue;
if (seqv != null)
return VisitSequenceValue(state, seqv);
var strv = value as StructureValue;
if (strv != null)
return VisitStructureValue(state, strv);
var dictv = value as DictionaryValue;
if (dictv != null)
return VisitDictionaryValue(state, dictv);
return VisitUnsupportedValue(state, value);
}
/// <summary>
/// Visit a <see cref="ScalarValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="scalar">The value to visit.</param>
/// <returns>The result of visiting <paramref name="scalar"/>.</returns>
protected abstract TResult VisitScalarValue(TState state, ScalarValue scalar);
/// <summary>
/// Visit a <see cref="SequenceValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="sequence">The value to visit.</param>
/// <returns>The result of visiting <paramref name="sequence"/>.</returns>
protected abstract TResult VisitSequenceValue(TState state, SequenceValue sequence);
/// <summary>
/// Visit a <see cref="StructureValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="structure">The value to visit.</param>
/// <returns>The result of visiting <paramref name="structure"/>.</returns>
protected abstract TResult VisitStructureValue(TState state, StructureValue structure);
/// <summary>
/// Visit a <see cref="DictionaryValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="dictionary">The value to visit.</param>
/// <returns>The result of visiting <paramref name="dictionary"/>.</returns>
protected abstract TResult VisitDictionaryValue(TState state, DictionaryValue dictionary);
/// <summary>
/// Visit a value of an unsupported type.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
// ReSharper disable once UnusedParameter.Global
protected virtual TResult VisitUnsupportedValue(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
throw new NotSupportedException($"The value {value} is not of a type supported by this visitor.");
}
Project:learning
File:LogEventPropertyValueVisitor.cs
Examples:6
/// <summary>
/// Visit the root node type. This method delegates to
/// a concrete Visit*Value() method appropriate for the value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
protected virtual TResult Visit(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
var sv = value as ScalarValue;
if (sv != null)
return VisitScalarValue(state, sv);
var seqv = value as SequenceValue;
if (seqv != null)
return VisitSequenceValue(state, seqv);
var strv = value as StructureValue;
if (strv != null)
return VisitStructureValue(state, strv);
var dictv = value as DictionaryValue;
if (dictv != null)
return VisitDictionaryValue(state, dictv);
return VisitUnsupportedValue(state, value);
}
/// <summary>
/// Visit a <see cref="ScalarValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="scalar">The value to visit.</param>
/// <returns>The result of visiting <paramref name="scalar"/>.</returns>
protected abstract TResult VisitScalarValue(TState state, ScalarValue scalar);
/// <summary>
/// Visit a <see cref="SequenceValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="sequence">The value to visit.</param>
/// <returns>The result of visiting <paramref name="sequence"/>.</returns>
protected abstract TResult VisitSequenceValue(TState state, SequenceValue sequence);
/// <summary>
/// Visit a <see cref="StructureValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="structure">The value to visit.</param>
/// <returns>The result of visiting <paramref name="structure"/>.</returns>
protected abstract TResult VisitStructureValue(TState state, StructureValue structure);
/// <summary>
/// Visit a <see cref="DictionaryValue"/> value.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="dictionary">The value to visit.</param>
/// <returns>The result of visiting <paramref name="dictionary"/>.</returns>
protected abstract TResult VisitDictionaryValue(TState state, DictionaryValue dictionary);
/// <summary>
/// Visit a value of an unsupported type.
/// </summary>
/// <param name="state">Operation state.</param>
/// <param name="value">The value to visit.</param>
/// <returns>The result of visiting <paramref name="value"/>.</returns>
// ReSharper disable once UnusedParameter.Global
protected virtual TResult VisitUnsupportedValue(TState state, LogEventPropertyValue value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
throw new NotSupportedException($"The value {value} is not of a type supported by this visitor.");
}
Serilog.Data.LogEventPropertyValueVisitor<TState, TResult> : Object
Methods :
public Type GetType()public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()