Skip to content

Commit

Permalink
Merge pull request #8079 from AvaloniaUI/refactor/log-nongeneric
Browse files Browse the repository at this point in the history
Remove generic methods from ILogSink.
  • Loading branch information
maxkatz6 authored May 5, 2022
2 parents dbba50a + dfea124 commit 7382a96
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 103 deletions.
51 changes: 0 additions & 51 deletions src/Avalonia.Base/Logging/ILogSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,6 @@ void Log(
object? source,
string messageTemplate);

/// <summary>
/// Logs an event.
/// </summary>
/// <param name="level">The log event level.</param>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param>
void Log<T0>(
LogEventLevel level,
string area,
object? source,
string messageTemplate,
T0 propertyValue0);

/// <summary>
/// Logs an event.
/// </summary>
/// <param name="level">The log event level.</param>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param>
/// <param name="propertyValue1">Message property value.</param>
void Log<T0, T1>(
LogEventLevel level,
string area,
object? source,
string messageTemplate,
T0 propertyValue0,
T1 propertyValue1);

/// <summary>
/// Logs an event.
/// </summary>
/// <param name="level">The log event level.</param>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param>
/// <param name="propertyValue1">Message property value.</param>
/// <param name="propertyValue2">Message property value.</param>
void Log<T0, T1, T2>(
LogEventLevel level,
string area,
object? source,
string messageTemplate,
T0 propertyValue0,
T1 propertyValue1,
T2 propertyValue2);

/// <summary>
/// Logs a new event.
/// </summary>
Expand Down
38 changes: 3 additions & 35 deletions src/Avalonia.Base/Logging/TraceLogSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,7 @@ public void Log(LogEventLevel level, string area, object? source, string message
{
if (IsEnabled(level, area))
{
Trace.WriteLine(Format<object, object, object>(area, messageTemplate, source));
}
}

public void Log<T0>(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0)
{
if (IsEnabled(level, area))
{
Trace.WriteLine(Format<T0, object, object>(area, messageTemplate, source, propertyValue0));
}
}

public void Log<T0, T1>(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
if (IsEnabled(level, area))
{
Trace.WriteLine(Format<T0, T1, object>(area, messageTemplate, source, propertyValue0, propertyValue1));
}
}

public void Log<T0, T1, T2>(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
if (IsEnabled(level, area))
{
Trace.WriteLine(Format(area, messageTemplate, source, propertyValue0, propertyValue1, propertyValue2));
Trace.WriteLine(Format<object, object, object>(area, messageTemplate, source, null));
}
}

Expand All @@ -68,9 +44,7 @@ private static string Format<T0, T1, T2>(
string area,
string template,
object? source,
T0? v0 = default,
T1? v1 = default,
T2? v2 = default)
object?[]? values)
{
var result = new StringBuilder(template.Length);
var r = new CharacterReader(template.AsSpan());
Expand All @@ -93,13 +67,7 @@ private static string Format<T0, T1, T2>(
if (r.Peek != '{')
{
result.Append('\'');
result.Append(i++ switch
{
0 => v0,
1 => v1,
2 => v2,
_ => null
});
result.Append(values?[i++]);
result.Append('\'');
r.TakeUntil('}');
r.Take();
Expand Down
17 changes: 0 additions & 17 deletions tests/Avalonia.UnitTests/TestLogSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ public void Log(LogEventLevel level, string area, object source, string messageT
_callback(level, area, source, messageTemplate);
}

public void Log<T0>(LogEventLevel level, string area, object source, string messageTemplate, T0 propertyValue0)
{
_callback(level, area, source, messageTemplate, propertyValue0);
}

public void Log<T0, T1>(LogEventLevel level, string area, object source, string messageTemplate,
T0 propertyValue0, T1 propertyValue1)
{
_callback(level, area, source, messageTemplate, propertyValue0, propertyValue1);
}

public void Log<T0, T1, T2>(LogEventLevel level, string area, object source, string messageTemplate,
T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
_callback(level, area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}

public void Log(LogEventLevel level, string area, object source, string messageTemplate,
params object[] propertyValues)
{
Expand Down

0 comments on commit 7382a96

Please sign in to comment.