No meaningful code changes, just lots of namespace shuffling to have fewer namespaces and to put things in better namespaces.
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
|
|
namespace ModelContextProtocol.Tests.Utils;
|
|
|
|
public class XunitLoggerProvider(ITestOutputHelper output) : ILoggerProvider
|
|
{
|
|
public ILogger CreateLogger(string categoryName)
|
|
{
|
|
return new XunitLogger(output, categoryName);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
private class XunitLogger(ITestOutputHelper output, string category) : ILogger
|
|
{
|
|
public void Log<TState>(
|
|
LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
var timestamp = DateTimeOffset.UtcNow.ToString("s", CultureInfo.InvariantCulture);
|
|
var prefix = $"| [{timestamp}] {category} {logLevel}: ";
|
|
var lines = formatter(state, exception);
|
|
sb.Append(prefix);
|
|
sb.Append(lines);
|
|
|
|
if (exception is not null)
|
|
{
|
|
sb.AppendLine();
|
|
sb.Append(exception.ToString());
|
|
}
|
|
|
|
output.WriteLine(sb.ToString());
|
|
}
|
|
|
|
public bool IsEnabled(LogLevel logLevel) => true;
|
|
|
|
public IDisposable BeginScope<TState>(TState state) where TState : notnull
|
|
=> new NoopDisposable();
|
|
|
|
private sealed class NoopDisposable : IDisposable
|
|
{
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|