Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Added NullLoggerOfT to Logging.Abstractions #570

Merged
merged 1 commit into from
Mar 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/Microsoft.Extensions.Logging.Abstractions/NullLoggerOfT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace Microsoft.Extensions.Logging.Abstractions
{
/// <summary>
/// Minimalistic logger that does nothing.
/// </summary>
public class NullLogger<T> : ILogger<T>
{
public static readonly NullLogger<T> Instance = new NullLogger<T>();

/// <inheritdoc />
public IDisposable BeginScope<TState>(TState state)
{
return NullDisposable.Instance;
}

/// <inheritdoc />
/// <remarks>
/// This method ignores the parameters and does nothing.
/// </remarks>
public void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
{
}

/// <inheritdoc />
public bool IsEnabled(LogLevel logLevel)
{
return false;
}

private class NullDisposable : IDisposable
{
public static readonly NullDisposable Instance = new NullDisposable();

public void Dispose()
{
// intentionally does nothing
}
}
}
}