diff --git a/src/Logging/Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj b/src/Logging/Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj index 239c19b4705..77856fbad2b 100644 --- a/src/Logging/Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj +++ b/src/Logging/Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj @@ -14,4 +14,8 @@ Microsoft.Extensions.Logging.Abstractions.NullLogger $(NoWarn);CS1591 + + + + diff --git a/src/Logging/Logging.Abstractions/src/NullLogger.cs b/src/Logging/Logging.Abstractions/src/NullLogger.cs index 09b2afda5cf..b6926f4ebce 100644 --- a/src/Logging/Logging.Abstractions/src/NullLogger.cs +++ b/src/Logging/Logging.Abstractions/src/NullLogger.cs @@ -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 { diff --git a/src/Logging/Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj b/src/Logging/Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj index 20c63fbf6e6..ddd7d5af55a 100644 --- a/src/Logging/Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj +++ b/src/Logging/Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj @@ -7,6 +7,8 @@ + + diff --git a/src/Logging/Logging.Debug/src/DebugLogger.cs b/src/Logging/Logging.Debug/src/DebugLogger.cs index bd9daecac29..588892e92f1 100644 --- a/src/Logging/Logging.Debug/src/DebugLogger.cs +++ b/src/Logging/Logging.Debug/src/DebugLogger.cs @@ -9,35 +9,23 @@ namespace Microsoft.Extensions.Logging.Debug /// /// A logger that writes messages in the debug output window only when a debugger is attached. /// - public partial class DebugLogger : ILogger + internal partial class DebugLogger : ILogger { - private readonly Func _filter; private readonly string _name; /// /// Initializes a new instance of the class. /// /// The name of the logger. - public DebugLogger(string name) : this(name, filter: null) + public DebugLogger(string name) { + _name = name; } - /// - /// Initializes a new instance of the class. - /// - /// The name of the logger. - /// The function used to filter events based on the log level. - public DebugLogger(string name, Func filter) - { - _name = string.IsNullOrEmpty(name) ? nameof(DebugLogger) : name; - _filter = filter; - } - - /// public IDisposable BeginScope(TState state) { - return NoopDisposable.Instance; + return NullScope.Instance; } /// @@ -45,9 +33,7 @@ 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; } /// @@ -74,19 +60,10 @@ public void Log(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() - { - } - } } } diff --git a/src/Logging/Logging.Debug/src/DebugLogger.debug.cs b/src/Logging/Logging.Debug/src/DebugLogger.debug.cs index 2d3857fff32..b2857118151 100644 --- a/src/Logging/Logging.Debug/src/DebugLogger.debug.cs +++ b/src/Logging/Logging.Debug/src/DebugLogger.debug.cs @@ -8,7 +8,7 @@ namespace Microsoft.Extensions.Logging.Debug { - public partial class DebugLogger + internal partial class DebugLogger { private void DebugWriteLine(string message, string name) { diff --git a/src/Logging/Logging.Debug/src/DebugLoggerFactoryExtensions.cs b/src/Logging/Logging.Debug/src/DebugLoggerFactoryExtensions.cs index 047b90a4d48..26adf510299 100644 --- a/src/Logging/Logging.Debug/src/DebugLoggerFactoryExtensions.cs +++ b/src/Logging/Logging.Debug/src/DebugLoggerFactoryExtensions.cs @@ -23,40 +23,5 @@ public static ILoggingBuilder AddDebug(this ILoggingBuilder builder) return builder; } - - /// - /// Adds a debug logger that is enabled for .Information or higher. - /// - /// The extension method argument. - [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); - } - - /// - /// Adds a debug logger that is enabled as defined by the filter function. - /// - /// The extension method argument. - /// The function used to filter events based on the log level. - [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 filter) - { - factory.AddProvider(new DebugLoggerProvider(filter)); - return factory; - } - - /// - /// Adds a debug logger that is enabled for s of minLevel or higher. - /// - /// The extension method argument. - /// The minimum to be logged - [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); - } } -} \ No newline at end of file +} diff --git a/src/Logging/Logging.Debug/src/DebugLoggerProvider.cs b/src/Logging/Logging.Debug/src/DebugLoggerProvider.cs index e80bbb468cc..c283a40db53 100644 --- a/src/Logging/Logging.Debug/src/DebugLoggerProvider.cs +++ b/src/Logging/Logging.Debug/src/DebugLoggerProvider.cs @@ -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 { /// @@ -11,27 +9,10 @@ namespace Microsoft.Extensions.Logging.Debug [ProviderAlias("Debug")] public class DebugLoggerProvider : ILoggerProvider { - private readonly Func _filter; - - public DebugLoggerProvider() - { - _filter = null; - } - - /// - /// Initializes a new instance of the class. - /// - /// The function used to filter events based on the log level. - [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 filter) - { - _filter = filter; - } - /// public ILogger CreateLogger(string name) { - return new DebugLogger(name, _filter); + return new DebugLogger(name); } public void Dispose() diff --git a/src/Logging/Logging.Debug/src/Microsoft.Extensions.Logging.Debug.csproj b/src/Logging/Logging.Debug/src/Microsoft.Extensions.Logging.Debug.csproj index df87b239fed..993ff6e16cd 100644 --- a/src/Logging/Logging.Debug/src/Microsoft.Extensions.Logging.Debug.csproj +++ b/src/Logging/Logging.Debug/src/Microsoft.Extensions.Logging.Debug.csproj @@ -7,6 +7,8 @@ + + diff --git a/src/Logging/Logging.Debug/src/Properties/AssemblyInfo.cs b/src/Logging/Logging.Debug/src/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..32e0f3469ae --- /dev/null +++ b/src/Logging/Logging.Debug/src/Properties/AssemblyInfo.cs @@ -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")] diff --git a/src/Logging/Logging.Debug/src/breakingchanges.netcore.json b/src/Logging/Logging.Debug/src/breakingchanges.netcore.json new file mode 100644 index 00000000000..7f6bfcacb22 --- /dev/null +++ b/src/Logging/Logging.Debug/src/breakingchanges.netcore.json @@ -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 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 filter)", + "Kind": "Removal" + } +] \ No newline at end of file diff --git a/src/Logging/Logging.EventLog/src/EventLogLogger.cs b/src/Logging/Logging.EventLog/src/EventLogLogger.cs index 82c438145d7..8732b62ac8e 100644 --- a/src/Logging/Logging.EventLog/src/EventLogLogger.cs +++ b/src/Logging/Logging.EventLog/src/EventLogLogger.cs @@ -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 { /// /// A logger that writes messages to Windows Event Log. /// - [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; @@ -22,15 +19,6 @@ public class EventLogLogger : ILogger private readonly int _beginOrEndMessageSegmentSize; private readonly int _intermediateMessageSegmentSize; - /// - /// Initializes a new instance of the class. - /// - /// The name of the logger. - public EventLogLogger(string name) - : this(name, settings: new EventLogSettings()) - { - } - /// /// Initializes a new instance of the class. /// @@ -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() - { - } - } } } diff --git a/src/Logging/Logging.EventLog/src/EventLogLoggerProvider.cs b/src/Logging/Logging.EventLog/src/EventLogLoggerProvider.cs index 3e88b780009..8bff36fd8dc 100644 --- a/src/Logging/Logging.EventLog/src/EventLogLoggerProvider.cs +++ b/src/Logging/Logging.EventLog/src/EventLogLoggerProvider.cs @@ -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 { /// @@ -35,10 +33,7 @@ public EventLogLoggerProvider(EventLogSettings settings) /// 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() diff --git a/src/Logging/Logging.EventLog/src/EventLogSettings.cs b/src/Logging/Logging.EventLog/src/EventLogSettings.cs index d04470158b7..96558ba5c2c 100644 --- a/src/Logging/Logging.EventLog/src/EventLogSettings.cs +++ b/src/Logging/Logging.EventLog/src/EventLogSettings.cs @@ -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 { @@ -34,6 +33,6 @@ public class EventLogSettings /// /// For unit testing purposes only. /// - public IEventLog EventLog { get; set; } + internal IEventLog EventLog { get; set; } } } diff --git a/src/Logging/Logging.EventLog/src/EventLoggerFactoryExtensions.cs b/src/Logging/Logging.EventLog/src/EventLoggerFactoryExtensions.cs index 73588082416..df79985582c 100644 --- a/src/Logging/Logging.EventLog/src/EventLoggerFactoryExtensions.cs +++ b/src/Logging/Logging.EventLog/src/EventLoggerFactoryExtensions.cs @@ -50,63 +50,5 @@ public static ILoggingBuilder AddEventLog(this ILoggingBuilder builder, EventLog return builder; } - - /// - /// Adds an event logger that is enabled for .Information or higher. - /// - /// The extension method argument. - [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); - } - - /// - /// Adds an event logger that is enabled for s of minLevel or higher. - /// - /// The extension method argument. - /// The minimum to be logged - [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 - }); - } - - /// - /// Adds an event logger. Use to enable logging for specific s. - /// - /// The extension method argument. - /// The . - [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; - } } } diff --git a/src/Logging/Logging.EventLog/src/Internal/IEventLog.cs b/src/Logging/Logging.EventLog/src/IEventLog.cs similarity index 66% rename from src/Logging/Logging.EventLog/src/Internal/IEventLog.cs rename to src/Logging/Logging.EventLog/src/IEventLog.cs index b1a255c4a9b..eee5d8b427b 100644 --- a/src/Logging/Logging.EventLog/src/Internal/IEventLog.cs +++ b/src/Logging/Logging.EventLog/src/IEventLog.cs @@ -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; } diff --git a/src/Logging/Logging.EventLog/src/Properties/AssemblyInfo.cs b/src/Logging/Logging.EventLog/src/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..32e0f3469ae --- /dev/null +++ b/src/Logging/Logging.EventLog/src/Properties/AssemblyInfo.cs @@ -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")] diff --git a/src/Logging/Logging.EventLog/src/WindowsEventLog.cs b/src/Logging/Logging.EventLog/src/WindowsEventLog.cs index 23c7c0403df..3a757b611f4 100644 --- a/src/Logging/Logging.EventLog/src/WindowsEventLog.cs +++ b/src/Logging/Logging.EventLog/src/WindowsEventLog.cs @@ -1,14 +1,11 @@ // 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; using System.Diagnostics; -using Microsoft.Extensions.Logging.EventLog.Internal; namespace Microsoft.Extensions.Logging.EventLog { - [Obsolete("This type is obsolete and will be removed in a future version. The recommended alternative is using EventLogLoggerProvider.")] - public class WindowsEventLog : IEventLog + internal class WindowsEventLog : IEventLog { // https://msdn.microsoft.com/EN-US/library/windows/desktop/aa363679.aspx private const int MaximumMessageSize = 31839; @@ -20,13 +17,7 @@ public WindowsEventLog(string logName, string machineName, string sourceName) public System.Diagnostics.EventLog DiagnosticsEventLog { get; } - public int MaxMessageSize - { - get - { - return MaximumMessageSize; - } - } + public int MaxMessageSize => MaximumMessageSize; public void WriteEntry(string message, EventLogEntryType type, int eventID, short category) { diff --git a/src/Logging/Logging.EventLog/src/breakingchanges.netcore.json b/src/Logging/Logging.EventLog/src/breakingchanges.netcore.json new file mode 100644 index 00000000000..47ad5f5b177 --- /dev/null +++ b/src/Logging/Logging.EventLog/src/breakingchanges.netcore.json @@ -0,0 +1,35 @@ +[ + { + "TypeId": "public class Microsoft.Extensions.Logging.EventLog.EventLogLogger : Microsoft.Extensions.Logging.ILogger", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.Extensions.Logging.EventLog.WindowsEventLog : Microsoft.Extensions.Logging.EventLog.Internal.IEventLog", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.Extensions.Logging.EventLog.EventLogSettings", + "MemberId": "public Microsoft.Extensions.Logging.EventLog.Internal.IEventLog get_EventLog()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.Extensions.Logging.EventLog.EventLogSettings", + "MemberId": "public System.Void set_EventLog(Microsoft.Extensions.Logging.EventLog.Internal.IEventLog value)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.EventLoggerFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddEventLog(this Microsoft.Extensions.Logging.ILoggerFactory factory)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.EventLoggerFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddEventLog(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Logging.EventLog.EventLogSettings settings)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.EventLoggerFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddEventLog(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Logging.LogLevel minLevel)", + "Kind": "Removal" + } +] \ No newline at end of file diff --git a/src/Logging/Logging.EventLog/src/breakingchanges.netframework.json b/src/Logging/Logging.EventLog/src/breakingchanges.netframework.json new file mode 100644 index 00000000000..44e86c2bd47 --- /dev/null +++ b/src/Logging/Logging.EventLog/src/breakingchanges.netframework.json @@ -0,0 +1,35 @@ +[ + { + "TypeId": "public class Microsoft.Extensions.Logging.EventLog.EventLogLogger : Microsoft.Extensions.Logging.ILogger", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.Extensions.Logging.EventLog.WindowsEventLog : Microsoft.Extensions.Logging.EventLog.Internal.IEventLog", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.Extensions.Logging.EventLog.EventLogSettings", + "MemberId": "public Microsoft.Extensions.Logging.EventLog.Internal.IEventLog get_EventLog()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.Extensions.Logging.EventLog.EventLogSettings", + "MemberId": "public System.Void set_EventLog(Microsoft.Extensions.Logging.EventLog.Internal.IEventLog value)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.EventLoggerFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddEventLog(this Microsoft.Extensions.Logging.ILoggerFactory factory)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.EventLoggerFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddEventLog(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Logging.EventLog.EventLogSettings settings)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.EventLoggerFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddEventLog(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Logging.LogLevel minLevel)", + "Kind": "Removal" + } + ] \ No newline at end of file diff --git a/src/Logging/Logging.EventSource/src/EventSourceLogger.cs b/src/Logging/Logging.EventSource/src/EventSourceLogger.cs index 553e1678857..8c93f92bd45 100644 --- a/src/Logging/Logging.EventSource/src/EventSourceLogger.cs +++ b/src/Logging/Logging.EventSource/src/EventSourceLogger.cs @@ -27,8 +27,8 @@ public EventSourceLogger(string categoryName, int factoryID, LoggingEventSource { CategoryName = categoryName; - // Default is to turn off logging - Level = LogLevel.None; + // Default is to turn on all the logging + Level = LogLevel.Trace; _factoryID = factoryID; _eventSource = eventSource; @@ -112,7 +112,7 @@ public IDisposable BeginScope(TState state) { if (!IsEnabled(LogLevel.Critical)) { - return NoopDisposable.Instance; + return NullScope.Instance; } var id = Interlocked.Increment(ref _activityIds); @@ -166,15 +166,6 @@ public void Dispose() } } - private class NoopDisposable : IDisposable - { - public static readonly NoopDisposable Instance = new NoopDisposable(); - - public void Dispose() - { - } - } - /// /// 'serializes' a given exception into an ExceptionInfo (that EventSource knows how to serialize) /// diff --git a/src/Logging/Logging.EventSource/src/EventSourceLoggerFactoryExtensions.cs b/src/Logging/Logging.EventSource/src/EventSourceLoggerFactoryExtensions.cs index ab29c49343d..92c6217148f 100644 --- a/src/Logging/Logging.EventSource/src/EventSourceLoggerFactoryExtensions.cs +++ b/src/Logging/Logging.EventSource/src/EventSourceLoggerFactoryExtensions.cs @@ -31,22 +31,5 @@ public static ILoggingBuilder AddEventSourceLogger(this ILoggingBuilder builder) builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, EventLogFiltersConfigureOptionsChangeSource>()); return builder; } - - /// - /// Adds an event logger that is enabled for .Information or higher. - /// - /// The extension method argument. - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddEventSourceLogger(this ILoggingBuilder builder).")] - public static ILoggerFactory AddEventSourceLogger(this ILoggerFactory factory) - { - if (factory == null) - { - throw new ArgumentNullException(nameof(factory)); - } - - factory.AddProvider(new EventSourceLoggerProvider(LoggingEventSource.Instance, handleFilters: true)); - - return factory; - } } } diff --git a/src/Logging/Logging.EventSource/src/EventSourceLoggerProvider.cs b/src/Logging/Logging.EventSource/src/EventSourceLoggerProvider.cs index 47280ef5daa..59696bbdac3 100644 --- a/src/Logging/Logging.EventSource/src/EventSourceLoggerProvider.cs +++ b/src/Logging/Logging.EventSource/src/EventSourceLoggerProvider.cs @@ -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 System.Diagnostics; using System.Threading; namespace Microsoft.Extensions.Logging.EventSource @@ -11,105 +10,41 @@ namespace Microsoft.Extensions.Logging.EventSource /// The provider for the . /// [ProviderAlias("EventSource")] - internal class EventSourceLoggerProvider : ILoggerProvider + public class EventSourceLoggerProvider : ILoggerProvider { private static int _globalFactoryID; // A small integer that uniquely identifies the LoggerFactory associated with this LoggingProvider. private readonly int _factoryID; - private LoggerFilterRule[] _rules; private EventSourceLogger _loggers; // Linked list of loggers that I have created private readonly LoggingEventSource _eventSource; - private readonly bool _handleFilters; - private IDisposable _filterChangeToken; - - public EventSourceLoggerProvider(LoggingEventSource eventSource) : this(eventSource, handleFilters: false) - { - - } - - public EventSourceLoggerProvider(LoggingEventSource eventSource, bool handleFilters) + /// + public EventSourceLoggerProvider(LoggingEventSource eventSource) { if (eventSource == null) { throw new ArgumentNullException(nameof(eventSource)); } _eventSource = eventSource; - _handleFilters = handleFilters; _factoryID = Interlocked.Increment(ref _globalFactoryID); - if (_handleFilters) - { - OnFilterConfigurationChange(); - } - } - - private void OnFilterConfigurationChange() - { - _filterChangeToken = _eventSource - .GetFilterChangeToken() - .RegisterChangeCallback(state => ((EventSourceLoggerProvider)state).OnFilterConfigurationChange(), this); - - SetFilterSpec(_eventSource.GetFilterRules()); } /// public ILogger CreateLogger(string categoryName) { - var newLogger = _loggers = new EventSourceLogger(categoryName, _factoryID, _eventSource, _loggers); - newLogger.Level = GetLoggerLevel(newLogger.CategoryName); - return newLogger; + return _loggers = new EventSourceLogger(categoryName, _factoryID, _eventSource, _loggers); } + /// public void Dispose() { - _filterChangeToken?.Dispose(); - // Turn off any logging for (var logger = _loggers; logger != null; logger = logger.Next) { logger.Level = LogLevel.None; } } - - // Sets the filtering for a particular logger provider - internal void SetFilterSpec(LoggerFilterRule[] rules) - { - _rules = rules; - - // Update the levels of all the loggers to match what the filter specification asks for. - for (var logger = _loggers; logger != null; logger = logger.Next) - { - logger.Level = GetLoggerLevel(logger.CategoryName); - } - } - - private LogLevel GetLoggerLevel(string loggerCategoryName) - { - if (!_handleFilters) - { - return LogLevel.Trace; - } - - var level = LogLevel.None; - foreach (var rule in _rules) - { - Debug.Assert(rule.LogLevel.HasValue); - Debug.Assert(rule.ProviderName == GetType().FullName); - - if (rule.CategoryName == null) - { - level = rule.LogLevel.Value; - } - else if (loggerCategoryName.StartsWith(rule.CategoryName)) - { - level = rule.LogLevel.Value; - break; - } - } - - return level; - } } } diff --git a/src/Logging/Logging.EventSource/src/LoggingEventSource.cs b/src/Logging/Logging.EventSource/src/LoggingEventSource.cs index d07609c908b..5d9084f05af 100644 --- a/src/Logging/Logging.EventSource/src/LoggingEventSource.cs +++ b/src/Logging/Logging.EventSource/src/LoggingEventSource.cs @@ -1,8 +1,7 @@ -// 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; -using System.Collections; using System.Collections.Generic; using System.Diagnostics.Tracing; using System.Threading; @@ -80,7 +79,7 @@ public sealed class LoggingEventSource : System.Diagnostics.Tracing.EventSource /// This is public from an EventSource consumer point of view, but since these defintions /// are not needed outside this class /// - public class Keywords + public static class Keywords { /// /// Meta events are evnets about the LoggingEventSource itself (that is they did not come from ILogger @@ -357,4 +356,4 @@ internal LoggerFilterRule[] GetFilterRules() return _filterSpec; } } -} \ No newline at end of file +} diff --git a/src/Logging/Logging.EventSource/src/Microsoft.Extensions.Logging.EventSource.csproj b/src/Logging/Logging.EventSource/src/Microsoft.Extensions.Logging.EventSource.csproj index 4325fb850cb..1dbe8d79563 100644 --- a/src/Logging/Logging.EventSource/src/Microsoft.Extensions.Logging.EventSource.csproj +++ b/src/Logging/Logging.EventSource/src/Microsoft.Extensions.Logging.EventSource.csproj @@ -7,6 +7,8 @@ + + diff --git a/src/Logging/Logging.EventSource/src/breakingchanges.netcore.json b/src/Logging/Logging.EventSource/src/breakingchanges.netcore.json new file mode 100644 index 00000000000..b86733d436c --- /dev/null +++ b/src/Logging/Logging.EventSource/src/breakingchanges.netcore.json @@ -0,0 +1,11 @@ +[ + { + "TypeId": "public static class Microsoft.Extensions.Logging.EventSourceLoggerFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddEventSourceLogger(this Microsoft.Extensions.Logging.ILoggerFactory factory)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.Extensions.Logging.EventSource.LoggingEventSource+Keywords", + "Kind": "Removal" + } + ] \ No newline at end of file diff --git a/src/Logging/Logging.EventSource/test/EventSourceLoggerTest.cs b/src/Logging/Logging.EventSource/test/EventSourceLoggerTest.cs index 16e614d4ead..524a29a6fd7 100644 --- a/src/Logging/Logging.EventSource/test/EventSourceLoggerTest.cs +++ b/src/Logging/Logging.EventSource/test/EventSourceLoggerTest.cs @@ -1,4 +1,4 @@ -// 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; @@ -11,53 +11,26 @@ using Xunit; using Microsoft.Extensions.DependencyInjection; -// AddEventSourceLogger(ILoggerProvider) overload is obsolete -#pragma warning disable CS0618 // Type or member is obsolete - namespace Microsoft.Extensions.Logging.Test { - public abstract class EventSourceLoggerTest: IDisposable + public class EventSourceLoggerTest: IDisposable { - public class EventSourceLoggerFactoryTest: EventSourceLoggerTest - { - private LoggerFactory _factory; + private ServiceProvider _serviceProvider; - protected override ILoggerFactory CreateLoggerFactory() - { - _factory = new LoggerFactory(); - _factory.AddEventSourceLogger(); - return _factory; - } + protected ILoggerFactory CreateLoggerFactory() + { + _serviceProvider = new ServiceCollection() + .AddLogging(builder => builder.AddEventSourceLogger()) + .BuildServiceProvider(); - public override void Dispose() - { - _factory.Dispose(); - } + return _serviceProvider.GetRequiredService(); } - public class EventSourceLoggerBuilderTest : EventSourceLoggerTest + public void Dispose() { - private ServiceProvider _serviceProvider; - - protected override ILoggerFactory CreateLoggerFactory() - { - _serviceProvider = new ServiceCollection() - .AddLogging(builder => builder.AddEventSourceLogger()) - .BuildServiceProvider(); - - return _serviceProvider.GetRequiredService(); - } - - public override void Dispose() - { - _serviceProvider?.Dispose(); - } + _serviceProvider?.Dispose(); } - protected abstract ILoggerFactory CreateLoggerFactory(); - - public abstract void Dispose(); - [Fact] public void IsEnabledReturnsCorrectValue() { diff --git a/src/Logging/Logging.TraceSource/src/TraceSourceFactoryExtensions.cs b/src/Logging/Logging.TraceSource/src/TraceSourceFactoryExtensions.cs index b419acb4ee6..d6ee1705186 100644 --- a/src/Logging/Logging.TraceSource/src/TraceSourceFactoryExtensions.cs +++ b/src/Logging/Logging.TraceSource/src/TraceSourceFactoryExtensions.cs @@ -80,7 +80,7 @@ public static ILoggingBuilder AddTraceSource( throw new ArgumentNullException(nameof(sourceSwitch)); } - builder.Services.AddSingleton(new TraceSourceLoggerProvider(sourceSwitch)); + builder.Services.AddSingleton(_ => new TraceSourceLoggerProvider(sourceSwitch)); return builder; } @@ -111,109 +111,9 @@ public static ILoggingBuilder AddTraceSource( throw new ArgumentNullException(nameof(listener)); } - builder.Services.AddSingleton(new TraceSourceLoggerProvider(sourceSwitch, listener)); + builder.Services.AddSingleton(_ => new TraceSourceLoggerProvider(sourceSwitch, listener)); return builder; } - - /// - /// - /// The to use. - /// The name of the to use. - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddTraceSource(this ILoggingBuilder builder).")] - public static ILoggerFactory AddTraceSource( - this ILoggerFactory factory, - string switchName) - { - if (factory == null) - { - throw new ArgumentNullException(nameof(factory)); - } - - if (switchName == null) - { - throw new ArgumentNullException(nameof(switchName)); - } - - return factory.AddTraceSource(new SourceSwitch(switchName)); - } - - /// The to use. - /// The name of the to use. - /// The to use. - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddTraceSource(this ILoggingBuilder builder).")] - public static ILoggerFactory AddTraceSource( - this ILoggerFactory factory, - string switchName, - TraceListener listener) - { - if (factory == null) - { - throw new ArgumentNullException(nameof(factory)); - } - - if (switchName == null) - { - throw new ArgumentNullException(nameof(switchName)); - } - - if (listener == null) - { - throw new ArgumentNullException(nameof(listener)); - } - - return factory.AddTraceSource(new SourceSwitch(switchName), listener); - } - - /// The to use. - /// The to use. - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddTraceSource(this ILoggingBuilder builder).")] - public static ILoggerFactory AddTraceSource( - this ILoggerFactory factory, - SourceSwitch sourceSwitch) - { - if (factory == null) - { - throw new ArgumentNullException(nameof(factory)); - } - - if (sourceSwitch == null) - { - throw new ArgumentNullException(nameof(sourceSwitch)); - } - - factory.AddProvider(new TraceSourceLoggerProvider(sourceSwitch)); - - return factory; - } - - /// The to use. - /// The to use. - /// The to use. - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is AddTraceSource(this ILoggingBuilder builder).")] - public static ILoggerFactory AddTraceSource( - this ILoggerFactory factory, - SourceSwitch sourceSwitch, - TraceListener listener) - { - if (factory == null) - { - throw new ArgumentNullException(nameof(factory)); - } - - if (sourceSwitch == null) - { - throw new ArgumentNullException(nameof(sourceSwitch)); - } - - if (listener == null) - { - throw new ArgumentNullException(nameof(listener)); - } - - factory.AddProvider(new TraceSourceLoggerProvider(sourceSwitch, listener)); - - return factory; - } } -} \ No newline at end of file +} diff --git a/src/Logging/Logging.TraceSource/src/TraceSourceLogger.cs b/src/Logging/Logging.TraceSource/src/TraceSourceLogger.cs index 610b758ef77..0ebea6ee520 100644 --- a/src/Logging/Logging.TraceSource/src/TraceSourceLogger.cs +++ b/src/Logging/Logging.TraceSource/src/TraceSourceLogger.cs @@ -7,8 +7,7 @@ namespace Microsoft.Extensions.Logging.TraceSource { - [Obsolete("This type is obsolete and will be removed in a future version. The recommended alternative is using TraceSourceLoggerProvider to construct loggers.")] - public class TraceSourceLogger : ILogger + internal class TraceSourceLogger : ILogger { private readonly DiagnosticsTraceSource _traceSource; @@ -74,4 +73,4 @@ public IDisposable BeginScope(TState state) return new TraceSourceScope(state); } } -} \ No newline at end of file +} diff --git a/src/Logging/Logging.TraceSource/src/TraceSourceLoggerProvider.cs b/src/Logging/Logging.TraceSource/src/TraceSourceLoggerProvider.cs index 970b7d9fed8..13fd3a9fb96 100644 --- a/src/Logging/Logging.TraceSource/src/TraceSourceLoggerProvider.cs +++ b/src/Logging/Logging.TraceSource/src/TraceSourceLoggerProvider.cs @@ -53,10 +53,7 @@ public TraceSourceLoggerProvider(SourceSwitch rootSourceSwitch, TraceListener ro /// public ILogger CreateLogger(string name) { - // TraceSourceLogger is obsolete -#pragma warning disable CS0618 // Type or member is obsolete return new TraceSourceLogger(GetOrAddTraceSource(name)); -#pragma warning restore CS0618 } private DiagnosticsTraceSource GetOrAddTraceSource(string name) diff --git a/src/Logging/Logging.TraceSource/src/TraceSourceScope.cs b/src/Logging/Logging.TraceSource/src/TraceSourceScope.cs index ab57b8f5316..323d152afe1 100644 --- a/src/Logging/Logging.TraceSource/src/TraceSourceScope.cs +++ b/src/Logging/Logging.TraceSource/src/TraceSourceScope.cs @@ -9,8 +9,7 @@ namespace Microsoft.Extensions.Logging.TraceSource /// /// Provides an IDisposable that represents a logical operation scope based on System.Diagnostics LogicalOperationStack /// - [Obsolete("This type is obsolete and will be removed in a future version. This type is part of TraceSource logger implementation and shouldn't be used directly")] - public class TraceSourceScope : IDisposable + internal class TraceSourceScope : IDisposable { // To detect redundant calls private bool _isDisposed; diff --git a/src/Logging/Logging.TraceSource/src/breakingchanges.netcore.json b/src/Logging/Logging.TraceSource/src/breakingchanges.netcore.json new file mode 100644 index 00000000000..20a4f100c50 --- /dev/null +++ b/src/Logging/Logging.TraceSource/src/breakingchanges.netcore.json @@ -0,0 +1,30 @@ +[ + { + "TypeId": "public class Microsoft.Extensions.Logging.TraceSource.TraceSourceLogger : Microsoft.Extensions.Logging.ILogger", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.Extensions.Logging.TraceSource.TraceSourceScope : System.IDisposable", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.TraceSourceFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddTraceSource(this Microsoft.Extensions.Logging.ILoggerFactory factory, System.Diagnostics.SourceSwitch sourceSwitch)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.TraceSourceFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddTraceSource(this Microsoft.Extensions.Logging.ILoggerFactory factory, System.Diagnostics.SourceSwitch sourceSwitch, System.Diagnostics.TraceListener listener)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.TraceSourceFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddTraceSource(this Microsoft.Extensions.Logging.ILoggerFactory factory, System.String switchName)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.Extensions.Logging.TraceSourceFactoryExtensions", + "MemberId": "public static Microsoft.Extensions.Logging.ILoggerFactory AddTraceSource(this Microsoft.Extensions.Logging.ILoggerFactory factory, System.String switchName, System.Diagnostics.TraceListener listener)", + "Kind": "Removal" + } +] \ No newline at end of file diff --git a/src/Logging/Logging/src/Microsoft.Extensions.Logging.csproj b/src/Logging/Logging/src/Microsoft.Extensions.Logging.csproj index 95e47aeb620..54aa595329f 100644 --- a/src/Logging/Logging/src/Microsoft.Extensions.Logging.csproj +++ b/src/Logging/Logging/src/Microsoft.Extensions.Logging.csproj @@ -7,6 +7,8 @@ + + diff --git a/src/Logging/Logging.Abstractions/src/NullExternalScopeProvider.cs b/src/Logging/shared/NullExternalScopeProvider.cs similarity index 87% rename from src/Logging/Logging.Abstractions/src/NullExternalScopeProvider.cs rename to src/Logging/shared/NullExternalScopeProvider.cs index 9625d4e2d58..d66886e01c5 100644 --- a/src/Logging/Logging.Abstractions/src/NullExternalScopeProvider.cs +++ b/src/Logging/shared/NullExternalScopeProvider.cs @@ -2,14 +2,13 @@ // 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 { /// /// Scope provider that does nothing. /// - public class NullExternalScopeProvider : IExternalScopeProvider + internal class NullExternalScopeProvider : IExternalScopeProvider { private NullExternalScopeProvider() { diff --git a/src/Logging/Logging.Abstractions/src/Internal/NullScope.cs b/src/Logging/shared/NullScope.cs similarity index 72% rename from src/Logging/Logging.Abstractions/src/Internal/NullScope.cs rename to src/Logging/shared/NullScope.cs index 3b185652a0b..709cfd90fcc 100644 --- a/src/Logging/Logging.Abstractions/src/Internal/NullScope.cs +++ b/src/Logging/shared/NullScope.cs @@ -1,14 +1,14 @@ -// 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; -namespace Microsoft.Extensions.Logging.Abstractions.Internal +namespace Microsoft.Extensions.Logging { /// /// An empty scope without any logic /// - public class NullScope : IDisposable + internal class NullScope : IDisposable { public static NullScope Instance { get; } = new NullScope(); diff --git a/src/Logging/test/ConsoleLoggerTest.cs b/src/Logging/test/ConsoleLoggerTest.cs index 0789cd15786..9ce979ceca2 100644 --- a/src/Logging/test/ConsoleLoggerTest.cs +++ b/src/Logging/test/ConsoleLoggerTest.cs @@ -11,9 +11,6 @@ using Microsoft.Extensions.Options; using Xunit; -// ConsoleLogger is obsolete -#pragma warning disable CS0618 // Type or member is obsolete - namespace Microsoft.Extensions.Logging.Test { public class ConsoleLoggerTest diff --git a/src/Logging/test/DebugLoggerTest.cs b/src/Logging/test/DebugLoggerTest.cs index 58d5caa8d9b..41f0860d039 100644 --- a/src/Logging/test/DebugLoggerTest.cs +++ b/src/Logging/test/DebugLoggerTest.cs @@ -1,8 +1,8 @@ // 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; using Microsoft.Extensions.Logging.Debug; +using Microsoft.Extensions.Logging.Test; using Xunit; namespace Microsoft.Extensions.Logging @@ -13,7 +13,7 @@ public class DebugLoggerTest public void CallingBeginScopeOnLogger_ReturnsNonNullableInstance() { // Arrange - var logger = new DebugLogger("Test"); + var logger = CreateLogger(); // Act var disposable = logger.BeginScope("Scope1"); @@ -26,7 +26,7 @@ public void CallingBeginScopeOnLogger_ReturnsNonNullableInstance() public void CallingLogWithCurlyBracesAfterFormatter_DoesNotThrow() { // Arrange - var logger = new DebugLogger("Test"); + var logger = CreateLogger(); var message = "{test string}"; // Act @@ -37,10 +37,15 @@ public void CallingLogWithCurlyBracesAfterFormatter_DoesNotThrow() public static void IsEnabledReturnsCorrectValue() { // Arrange - var logger = new DebugLogger("Test"); + var logger = CreateLogger(); // Assert Assert.False(logger.IsEnabled(LogLevel.None)); } + + private static ILogger CreateLogger() + { + return TestLoggerBuilder.Create(builder => builder.AddDebug()).CreateLogger("Test"); + } } } diff --git a/src/Logging/test/EventLogLoggerTest.cs b/src/Logging/test/EventLogLoggerTest.cs index 172ae58c461..a456e1ad266 100644 --- a/src/Logging/test/EventLogLoggerTest.cs +++ b/src/Logging/test/EventLogLoggerTest.cs @@ -6,12 +6,8 @@ using System.Diagnostics; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging.EventLog; -using Microsoft.Extensions.Logging.EventLog.Internal; using Xunit; -// EventLogLogger is obsolete -#pragma warning disable CS0618 // Type or member is obsolete - namespace Microsoft.Extensions.Logging { [OSSkipCondition(OperatingSystems.Linux)] @@ -41,7 +37,7 @@ public static void IsEnabledReturnsCorrectValue() public void CallingBeginScopeOnLogger_ReturnsNonNullableInstance() { // Arrange - var logger = new EventLogLogger("Test"); + var logger = new EventLogLogger("Test", new EventLogSettings()); // Act var disposable = logger.BeginScope("Scope1"); @@ -72,7 +68,7 @@ public void WindowsEventLog_Constructor_CreatesWithExpectedInformation() public void Constructor_CreatesWindowsEventLog_WithExpectedInformation() { // Arrange & Act - var eventLogLogger = new EventLogLogger("Test"); + var eventLogLogger = new EventLogLogger("Test", new EventLogSettings()); // Assert var windowsEventLog = Assert.IsType(eventLogLogger.EventLog); @@ -235,4 +231,4 @@ public void WriteEntry(string message, EventLogEntryType type, int eventID, shor } } } -} \ No newline at end of file +} diff --git a/src/Logging/test/TestLoggerBuilder.cs b/src/Logging/test/TestLoggerBuilder.cs index 015c281c1fd..70f593284f4 100644 --- a/src/Logging/test/TestLoggerBuilder.cs +++ b/src/Logging/test/TestLoggerBuilder.cs @@ -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 Castle.Core.Logging; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.Extensions.Logging.Test diff --git a/src/Logging/test/TestLoggerProvider.cs b/src/Logging/test/TestLoggerProvider.cs index 3dac9375ae2..54a9e999749 100644 --- a/src/Logging/test/TestLoggerProvider.cs +++ b/src/Logging/test/TestLoggerProvider.cs @@ -1,4 +1,4 @@ -// 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; @@ -45,4 +45,4 @@ public TestLoggerProvider2(TestSink testSink) : base(testSink, true) { } } -} \ No newline at end of file +} diff --git a/src/Logging/test/TraceSourceLoggerProviderTest.cs b/src/Logging/test/TraceSourceLoggerProviderTest.cs index ae68027a721..c56c52a9a27 100644 --- a/src/Logging/test/TraceSourceLoggerProviderTest.cs +++ b/src/Logging/test/TraceSourceLoggerProviderTest.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.Extensions.Logging.TraceSource; +using Microsoft.Extensions.DependencyInjection; using Xunit; namespace Microsoft.Extensions.Logging.Test @@ -20,14 +20,18 @@ public void Dispose_TraceListenerIsFlushedOnce() testSwitch.Level = SourceLevels.Warning; var listener = new BufferedConsoleTraceListener(); - TraceSourceLoggerProvider provider = new TraceSourceLoggerProvider(testSwitch, listener); - var logger1 = provider.CreateLogger("FirstLogger"); - var logger2 = provider.CreateLogger("SecondLogger"); + var serviceProvider = new ServiceCollection() + .AddLogging(builder => builder.AddTraceSource(testSwitch, listener)) + .BuildServiceProvider(); + + var factory = serviceProvider.GetRequiredService(); + var logger1 = factory.CreateLogger("FirstLogger"); + var logger2 = factory.CreateLogger("SecondLogger"); logger1.LogError("message1"); logger2.LogError("message2"); // Act - provider.Dispose(); + serviceProvider.Dispose(); // Assert Assert.Equal(1, listener.FlushCount);