-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
LoggerT.cs
50 lines (43 loc) · 1.6 KB
/
LoggerT.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using Microsoft.Extensions.Internal;
namespace Microsoft.Extensions.Logging
{
/// <summary>
/// Delegates to a new <see cref="ILogger"/> instance using the full name of the given type, created by the
/// provided <see cref="ILoggerFactory"/>.
/// </summary>
/// <typeparam name="T">The type.</typeparam>
public class Logger<T> : ILogger<T>
{
private readonly ILogger _logger;
/// <summary>
/// Creates a new <see cref="Logger{T}"/>.
/// </summary>
/// <param name="factory">The factory.</param>
public Logger(ILoggerFactory factory)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}
_logger = factory.CreateLogger(TypeNameHelper.GetTypeDisplayName(typeof(T), includeGenericParameters: false, nestedTypeDelimiter: '.'));
}
/// <inheritdoc />
IDisposable ILogger.BeginScope<TState>(TState state)
{
return _logger.BeginScope(state);
}
/// <inheritdoc />
bool ILogger.IsEnabled(LogLevel logLevel)
{
return _logger.IsEnabled(logLevel);
}
/// <inheritdoc />
void ILogger.Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
_logger.Log(logLevel, eventId, state, exception, formatter);
}
}
}