Files
agent-framework/dotnet/src/Shared/Samples/XunitLogger.cs
T
Roger Barreto 2c75f13337 .Net: Add ChatClientAgent Samples - OpenAI Model Client (#72)
* Add Streaming API

* Removing InstructionsRole

* Updating thread notification strategy

* Fix net472 failing

* Small fixes

* Adding Samples for OpenAI

* WIP samples

* default runsettings for unit tests

* Adding first samples with OpenAIModelChatClientAgents

* Removing OpenAI dependency on the sample utility

* Release -> Debug update for GettingStarted project

* Fix GettingStarted.csproj failing to build in Release

* Update dotnet/src/Shared/Samples/BaseSample.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Address PR feedback

* Fix Step 1 samples

* Simplify code

* Address PR feedback

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-12 12:22:07 +00:00

43 lines
1.3 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Extensions.Logging;
namespace Microsoft.Shared.SampleUtilities;
/// <summary>
/// A logger that writes to the Xunit test output
/// </summary>
internal sealed class XunitLogger(ITestOutputHelper output) : ILoggerFactory, ILogger, IDisposable
{
private object? _scopeState;
/// <inheritdoc/>
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
var localState = state?.ToString();
var line = this._scopeState is not null ? $"{this._scopeState} {localState}" : localState;
output.WriteLine(line);
}
/// <inheritdoc/>
public bool IsEnabled(LogLevel logLevel) => true;
/// <inheritdoc/>
public IDisposable BeginScope<TState>(TState state) where TState : notnull
{
this._scopeState = state;
return this;
}
/// <inheritdoc/>
public void Dispose()
{
// This class is marked as disposable to support the BeginScope method.
// However, there is no need to dispose anything.
}
public ILogger CreateLogger(string categoryName) => this;
public void AddProvider(ILoggerProvider provider) => throw new NotSupportedException();
}