Fix dev-integrated samples and remove MemoryLogger

This commit is contained in:
Caelan Sayler
2025-03-03 21:57:57 +00:00
committed by Caelan
parent 373b218dad
commit 3ba3ad4d7b
9 changed files with 35 additions and 141 deletions

View File

@@ -1,44 +0,0 @@
using System;
using System.Text;
using Microsoft.Extensions.Logging;
namespace CSharpAvalonia;
public class LogUpdatedEventArgs : EventArgs
{
public string Text { get; set; }
}
public class MemoryLogger : ILogger
{
public event EventHandler<LogUpdatedEventArgs> LogUpdated;
private readonly StringBuilder _sb = new StringBuilder();
public IDisposable BeginScope<TState>(TState state)
{
return null;
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
lock (_sb) {
var message = formatter(state, exception);
if (exception != null) message += "\n" + exception.ToString();
Console.WriteLine("log: " + message);
_sb.AppendLine(message);
LogUpdated?.Invoke(this, new LogUpdatedEventArgs { Text = _sb.ToString() });
}
}
public override string ToString()
{
lock (_sb) {
return _sb.ToString();
}
}
}