Skip to content

Remove obsolete types from Debug/Trace/EventLog types #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ Microsoft.Extensions.Logging.Abstractions.NullLogger</Description>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<Compile Include="../../shared/*.cs" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/Logging/Logging.Abstractions/src/NullLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.Logging.Abstractions.Internal;

namespace Microsoft.Extensions.Logging.Abstractions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="../../shared/*.cs" />

<Reference Include="Microsoft.Extensions.Configuration.Abstractions" />
<Reference Include="Microsoft.Extensions.Logging.Configuration" />
<Reference Include="Microsoft.Extensions.Logging" />
Expand Down
35 changes: 6 additions & 29 deletions src/Logging/Logging.Debug/src/DebugLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,31 @@ namespace Microsoft.Extensions.Logging.Debug
/// <summary>
/// A logger that writes messages in the debug output window only when a debugger is attached.
/// </summary>
public partial class DebugLogger : ILogger
internal partial class DebugLogger : ILogger
{
private readonly Func<string, LogLevel, bool> _filter;
private readonly string _name;

/// <summary>
/// Initializes a new instance of the <see cref="DebugLogger"/> class.
/// </summary>
/// <param name="name">The name of the logger.</param>
public DebugLogger(string name) : this(name, filter: null)
public DebugLogger(string name)
{
_name = name;
}

/// <summary>
/// Initializes a new instance of the <see cref="DebugLogger"/> class.
/// </summary>
/// <param name="name">The name of the logger.</param>
/// <param name="filter">The function used to filter events based on the log level.</param>
public DebugLogger(string name, Func<string, LogLevel, bool> filter)
{
_name = string.IsNullOrEmpty(name) ? nameof(DebugLogger) : name;
_filter = filter;
}


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

/// <inheritdoc />
public bool IsEnabled(LogLevel logLevel)
{
// If the filter is null, everything is enabled
// unless the debugger is not attached
return Debugger.IsAttached &&
logLevel != LogLevel.None &&
(_filter == null || _filter(_name, logLevel));
return Debugger.IsAttached && logLevel != LogLevel.None;
}

/// <inheritdoc />
Expand All @@ -74,19 +60,10 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except

if (exception != null)
{
message += Environment.NewLine + Environment.NewLine + exception.ToString();
message += Environment.NewLine + Environment.NewLine + exception;
}

DebugWriteLine(message, _name);
}

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

public void Dispose()
{
}
}
}
}
2 changes: 1 addition & 1 deletion src/Logging/Logging.Debug/src/DebugLogger.debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.Extensions.Logging.Debug
{
public partial class DebugLogger
internal partial class DebugLogger
{
private void DebugWriteLine(string message, string name)
{
Expand Down
37 changes: 1 addition & 36 deletions src/Logging/Logging.Debug/src/DebugLoggerFactoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,5 @@ public static ILoggingBuilder AddDebug(this ILoggingBuilder builder)

return builder;
}

/// <summary>
/// Adds a debug logger that is enabled for <see cref="LogLevel"/>.Information or higher.
/// </summary>
/// <param name="factory">The extension method argument.</param>
[Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddDebug(this ILoggingBuilder builder).")]
public static ILoggerFactory AddDebug(this ILoggerFactory factory)
{
return AddDebug(factory, LogLevel.Information);
}

/// <summary>
/// Adds a debug logger that is enabled as defined by the filter function.
/// </summary>
/// <param name="factory">The extension method argument.</param>
/// <param name="filter">The function used to filter events based on the log level.</param>
[Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddDebug(this ILoggingBuilder builder).")]
public static ILoggerFactory AddDebug(this ILoggerFactory factory, Func<string, LogLevel, bool> filter)
{
factory.AddProvider(new DebugLoggerProvider(filter));
return factory;
}

/// <summary>
/// Adds a debug logger that is enabled for <see cref="LogLevel"/>s of minLevel or higher.
/// </summary>
/// <param name="factory">The extension method argument.</param>
/// <param name="minLevel">The minimum <see cref="LogLevel"/> to be logged</param>
[Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddDebug(this ILoggingBuilder builder).")]
public static ILoggerFactory AddDebug(this ILoggerFactory factory, LogLevel minLevel)
{
return AddDebug(
factory,
(_, logLevel) => logLevel >= minLevel);
}
}
}
}
21 changes: 1 addition & 20 deletions src/Logging/Logging.Debug/src/DebugLoggerProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.Debug
{
/// <summary>
Expand All @@ -11,27 +9,10 @@ namespace Microsoft.Extensions.Logging.Debug
[ProviderAlias("Debug")]
public class DebugLoggerProvider : ILoggerProvider
{
private readonly Func<string, LogLevel, bool> _filter;

public DebugLoggerProvider()
{
_filter = null;
}

/// <summary>
/// Initializes a new instance of the <see cref="DebugLoggerProvider"/> class.
/// </summary>
/// <param name="filter">The function used to filter events based on the log level.</param>
[Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is using LoggerFactory to configure filtering.")]
public DebugLoggerProvider(Func<string, LogLevel, bool> filter)
{
_filter = filter;
}

/// <inheritdoc />
public ILogger CreateLogger(string name)
{
return new DebugLogger(name, _filter);
return new DebugLogger(name);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="../../shared/*.cs" />

<Reference Include="Microsoft.Extensions.Logging" />
</ItemGroup>

Expand Down
7 changes: 7 additions & 0 deletions src/Logging/Logging.Debug/src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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.Runtime.CompilerServices;


[assembly: InternalsVisibleTo("Microsoft.Extensions.Logging.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
26 changes: 26 additions & 0 deletions src/Logging/Logging.Debug/src/breakingchanges.netcore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"TypeId": "public class Microsoft.Extensions.Logging.Debug.DebugLogger : Microsoft.Extensions.Logging.ILogger",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.Extensions.Logging.Debug.DebugLoggerProvider : Microsoft.Extensions.Logging.ILoggerProvider",
"MemberId": "public .ctor(System.Func<System.String, Microsoft.Extensions.Logging.LogLevel, System.Boolean> filter)",
"Kind": "Removal"
},
{
"TypeId": "public static class Microsoft.Extensions.Logging.DebugLoggerFactoryExtensions",
"MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddDebug(this Microsoft.Extensions.Logging.ILoggerFactory factory)",
"Kind": "Removal"
},
{
"TypeId": "public static class Microsoft.Extensions.Logging.DebugLoggerFactoryExtensions",
"MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddDebug(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Logging.LogLevel minLevel)",
"Kind": "Removal"
},
{
"TypeId": "public static class Microsoft.Extensions.Logging.DebugLoggerFactoryExtensions",
"MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddDebug(this Microsoft.Extensions.Logging.ILoggerFactory factory, System.Func<System.String, Microsoft.Extensions.Logging.LogLevel, System.Boolean> filter)",
"Kind": "Removal"
}
]
23 changes: 1 addition & 22 deletions src/Logging/Logging.EventLog/src/EventLogLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Extensions.Logging.EventLog.Internal;

namespace Microsoft.Extensions.Logging.EventLog
{
/// <summary>
/// A logger that writes messages to Windows Event Log.
/// </summary>
[Obsolete("This type is obsolete and will be removed in a future version. The recommended alternative is using EventLogLoggerProvider to construct loggers.")]
public class EventLogLogger : ILogger
internal class EventLogLogger : ILogger
{
private readonly string _name;
private readonly EventLogSettings _settings;
Expand All @@ -22,15 +19,6 @@ public class EventLogLogger : ILogger
private readonly int _beginOrEndMessageSegmentSize;
private readonly int _intermediateMessageSegmentSize;

/// <summary>
/// Initializes a new instance of the <see cref="EventLogLogger"/> class.
/// </summary>
/// <param name="name">The name of the logger.</param>
public EventLogLogger(string name)
: this(name, settings: new EventLogSettings())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="EventLogLogger"/> class.
/// </summary>
Expand Down Expand Up @@ -188,14 +176,5 @@ private EventLogEntryType GetEventLogEntryType(LogLevel level)
return EventLogEntryType.Information;
}
}

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

public void Dispose()
{
}
}
}
}
7 changes: 1 addition & 6 deletions src/Logging/Logging.EventLog/src/EventLogLoggerProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.EventLog
{
/// <summary>
Expand Down Expand Up @@ -35,10 +33,7 @@ public EventLogLoggerProvider(EventLogSettings settings)
/// <inheritdoc />
public ILogger CreateLogger(string name)
{
// EventLogLogger is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
return new EventLogLogger(name, _settings ?? new EventLogSettings());
#pragma warning restore CS0618
return new EventLogLogger(name, _settings ?? new EventLogSettings(), _scopeProvider);
}

public void Dispose()
Expand Down
3 changes: 1 addition & 2 deletions src/Logging/Logging.EventLog/src/EventLogSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.Logging.EventLog.Internal;

namespace Microsoft.Extensions.Logging.EventLog
{
Expand Down Expand Up @@ -34,6 +33,6 @@ public class EventLogSettings
/// <summary>
/// For unit testing purposes only.
/// </summary>
public IEventLog EventLog { get; set; }
internal IEventLog EventLog { get; set; }
}
}
58 changes: 0 additions & 58 deletions src/Logging/Logging.EventLog/src/EventLoggerFactoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,63 +50,5 @@ public static ILoggingBuilder AddEventLog(this ILoggingBuilder builder, EventLog

return builder;
}

/// <summary>
/// Adds an event logger that is enabled for <see cref="LogLevel"/>.Information or higher.
/// </summary>
/// <param name="factory">The extension method argument.</param>
[Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddEventLog(this ILoggingBuilder builder).")]
public static ILoggerFactory AddEventLog(this ILoggerFactory factory)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}

return AddEventLog(factory, LogLevel.Information);
}

/// <summary>
/// Adds an event logger that is enabled for <see cref="LogLevel"/>s of minLevel or higher.
/// </summary>
/// <param name="factory">The extension method argument.</param>
/// <param name="minLevel">The minimum <see cref="LogLevel"/> to be logged</param>
[Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddEventLog(this ILoggingBuilder builder).")]
public static ILoggerFactory AddEventLog(this ILoggerFactory factory, LogLevel minLevel)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}

return AddEventLog(factory, new EventLogSettings()
{
Filter = (_, logLevel) => logLevel >= minLevel
});
}

/// <summary>
/// Adds an event logger. Use <paramref name="settings"/> to enable logging for specific <see cref="LogLevel"/>s.
/// </summary>
/// <param name="factory">The extension method argument.</param>
/// <param name="settings">The <see cref="EventLogSettings"/>.</param>
[Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddEventLog(this ILoggingBuilder builder).")]
public static ILoggerFactory AddEventLog(
this ILoggerFactory factory,
EventLogSettings settings)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}

if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}

factory.AddProvider(new EventLogLoggerProvider(settings));
return factory;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// 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.Diagnostics;

namespace Microsoft.Extensions.Logging.EventLog.Internal
namespace Microsoft.Extensions.Logging.EventLog
{
public interface IEventLog
internal interface IEventLog
{
int MaxMessageSize { get; }

Expand Down
Loading