mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-19 14:52:04 +08:00
4f28a55b48
Motivation .NET Core tooling allows building for both .NET Framework and .NET Standard while easing pains of running tests and packaging. Modifications - csproj -> xproj + project.json - support for .NET Standard 1.3 - build script is now based on CAKE - using dotnet CLI for building, testing, packing - strong name by default (snk included) Result DotNetty works on .NET Core and any other platform supporting .NET Standard 1.3+.
55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
namespace DotNetty.Tests.Common
|
|
{
|
|
using System;
|
|
using DotNetty.Common.Internal.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
public static class LogTestHelper
|
|
{
|
|
public static IDisposable SetInterceptionLogger(Intercept interceptAction)
|
|
{
|
|
InternalLoggerFactory.DefaultFactory.AddProvider(new InterceptionLoggerProvider(interceptAction));
|
|
return new Disposable(() => InternalLoggerFactory.DefaultFactory.AddProvider(new EventSourceLoggerProvider()));
|
|
}
|
|
|
|
public delegate void Intercept(string categoryName, LogLevel logLevel, EventId eventId, string message, Exception exception);
|
|
|
|
sealed class InterceptionLoggerProvider : ILoggerProvider
|
|
{
|
|
readonly Intercept interceptAction;
|
|
|
|
public InterceptionLoggerProvider(Intercept interceptAction)
|
|
{
|
|
this.interceptAction = interceptAction;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public ILogger CreateLogger(string categoryName) => new InterceptionLogger(categoryName, this.interceptAction);
|
|
}
|
|
|
|
sealed class InterceptionLogger : ILogger
|
|
{
|
|
readonly string categoryName;
|
|
readonly Intercept interceptAction;
|
|
|
|
public InterceptionLogger(string categoryName, Intercept interceptAction)
|
|
{
|
|
this.categoryName = categoryName;
|
|
this.interceptAction = interceptAction;
|
|
}
|
|
|
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
|
=> this.interceptAction(this.categoryName, logLevel, eventId, formatter(state, exception), exception);
|
|
|
|
public bool IsEnabled(LogLevel logLevel) => true;
|
|
|
|
public IDisposable BeginScope<TState>(TState state) => new Disposable(() => { });
|
|
}
|
|
}
|
|
} |