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

Commit 3036c16

Browse files
author
Oleksii Ruban
committed
Squashed commit of the following:
commit 05501d0 Author: David Fowler <[email protected]> Date: Fri Mar 25 02:27:23 2016 -0700 Fixed build commit 213f4ec Author: BrennanConroy <[email protected]> Date: Wed Mar 23 14:57:22 2016 -0700 Add missing tests from DNX451 -> NET451 rename commit ad487c7 Author: BrennanConroy <[email protected]> Date: Wed Mar 23 14:02:34 2016 -0700 Fix overload of Debug.WriteLine we are using commit 1f2c413 Author: Pranav K <[email protected]> Date: Tue Mar 22 09:40:22 2016 -0700 Revert "Revert "Reacting to CoreCLR package changes"" This reverts commit a63a9d0. commit c6bfb21 Author: Arthur Vickers <[email protected]> Date: Fri Mar 11 09:51:45 2016 -0800 Return IServiceCollection from AddLogging so that additional calls can be chained Previously the AddLogging method did this. It is also common in other builder methods like this. It doesn't do any harm for those that don't want to chain and allows cleaner code with fewer variable declarations for those that do. More details: We often write code like this: ```C#\ var appServiceProivder = new ServiceCollection() .AddLogging() .AddCaching() .BuildServiceProvider(); ``` This is really clean and easy to read. When we are no longer able to chain we have to write this instead: ```C# var serviceCollection = new ServiceCollection(); serviceCollection.AddLogging(); serviceCollection.AddCaching(); var appServiceProivder = serviceCollection.BuildServiceProvider(); ``` This additional clutter detracts from the overall readability of the code. Furthermore, the benefits of this kind of pattern are cascading. For example, it lets us use expression body syntax to again create very clear, very readable code: ```C# protected virtual void ConfigureServices([NotNull] IServiceCollection services) => services .AddSingleton<CSharpHelper>() .AddSingleton<CSharpMigrationOperationGenerator>() .AddSingleton<CSharpSnapshotGenerator>() .AddSingleton<MigrationsCodeGenerator, CSharpMigrationsGenerator>() .AddScaffolding() .AddLogging(); ``` This was the reason when these methods where designed a couple of years ago they allowed chaining. I'm not sure why we think this is no longer relevant. Also, returning the service collection as opposed to void doesn't force anybody to use chaining if they don't want to, so what is the downside? commit a63a9d0 Author: ryanbrandenburg <[email protected]> Date: Mon Mar 21 11:16:29 2016 -0700 Revert "Reacting to CoreCLR package changes" This reverts commit b4b1129. commit b4b1129 Author: Pranav K <[email protected]> Date: Sat Mar 19 10:34:45 2016 -0700 Reacting to CoreCLR package changes
1 parent 11e8bdf commit 3036c16

File tree

13 files changed

+57
-16
lines changed

13 files changed

+57
-16
lines changed

src/Microsoft.Extensions.Logging.Console/ConsoleLogger.cs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections;
6-
using System.Collections.Generic;
75
using System.Text;
86
using Microsoft.Extensions.Logging.Console.Internal;
97
using Microsoft.Extensions.PlatformAbstractions;

src/Microsoft.Extensions.Logging.Console/project.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
},
3030
"netstandard1.3": {
3131
"dependencies": {
32-
"System.Console": "4.0.0-*"
32+
"System.Console": "4.0.0-*",
33+
"System.Threading": "4.0.11-*"
3334
},
3435
"imports": [
3536
"dotnet5.4"

src/Microsoft.Extensions.Logging.Debug/DebugLogger.debug.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class DebugLogger
1212
{
1313
private void DebugWriteLine(string message, string name)
1414
{
15-
System.Diagnostics.Debug.WriteLine(message, name);
15+
System.Diagnostics.Debug.WriteLine(message, category: name);
1616
}
1717
}
1818
}

src/Microsoft.Extensions.Logging.Debug/project.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@
2020
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*"
2121
},
2222
"frameworks": {
23-
"netstandard1.1": {
23+
"net451": {
24+
"frameworkAssemblies": {
25+
"System.Runtime": { "type": "build" }
26+
}
27+
},
28+
"netstandard1.3": {
2429
"dependencies": {
2530
"System.Diagnostics.Debug": "4.0.11-*"
2631
},
2732
"imports": [
28-
"dotnet5.2"
33+
"dotnet5.4"
2934
]
3035
}
3136
}

src/Microsoft.Extensions.Logging/LoggingServiceCollectionExtensions.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public static class LoggingServiceCollectionExtensions
1616
/// Adds logging services to the specified <see cref="IServiceCollection" />.
1717
/// </summary>
1818
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
19-
public static void AddLogging(this IServiceCollection services)
19+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
20+
public static IServiceCollection AddLogging(this IServiceCollection services)
2021
{
2122
if (services == null)
2223
{
@@ -25,6 +26,8 @@ public static void AddLogging(this IServiceCollection services)
2526

2627
services.TryAdd(ServiceDescriptor.Singleton<ILoggerFactory, LoggerFactory>());
2728
services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(Logger<>)));
29+
30+
return services;
2831
}
2932
}
3033
}

test/Microsoft.Extensions.Logging.Test/DebugLoggerTest.cs

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using Microsoft.Extensions.Logging.Debug;
56
using Xunit;
67

@@ -36,5 +37,16 @@ public void CallingBeginScopeOnLogger_ReturnsNonNullableInstance()
3637
// Assert
3738
Assert.NotNull(disposable);
3839
}
40+
41+
[Fact]
42+
public void CallingLogWithCurlyBracesAfterFormatter_DoesNotThrow()
43+
{
44+
// Arrange
45+
var logger = new DebugLogger("Test");
46+
var message = "{test string}";
47+
48+
// Act
49+
logger.Log(LogLevel.Debug, 0, message, null, (s, e) => s);
50+
}
3951
}
4052
}

test/Microsoft.Extensions.Logging.Test/EventLogLoggerTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#if DNX451
4+
#if NET451
55
using System;
66
using System.Collections.Generic;
77
using System.Diagnostics;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Xunit;
6+
7+
namespace Microsoft.Extensions.Logging.Test
8+
{
9+
public class LoggingServiceCollectionExtensionsTest
10+
{
11+
[Fact]
12+
public void AddLogging_allows_chaining()
13+
{
14+
var services = new ServiceCollection();
15+
16+
Assert.Same(services, services.AddLogging());
17+
}
18+
}
19+
}

test/Microsoft.Extensions.Logging.Test/TraceSourceLoggerProviderTest.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#if DNX451
4+
#if NET451
55
using System.Diagnostics;
66
using Microsoft.Extensions.Logging.TraceSource;
77
using Xunit;
@@ -17,13 +17,13 @@ public void Dispose_TraceListenerIsFlushedOnce()
1717
var testSwitch = new SourceSwitch("TestSwitch", "Level will be set to warning for this test");
1818
testSwitch.Level = SourceLevels.Warning;
1919
var listener = new BufferedConsoleTraceListener();
20-
20+
2121
TraceSourceLoggerProvider provider = new TraceSourceLoggerProvider(testSwitch, listener);
2222
var logger1 = provider.CreateLogger("FirstLogger");
2323
var logger2 = provider.CreateLogger("SecondLogger");
2424
logger1.LogError("message1");
2525
logger2.LogError("message2");
26-
26+
2727
// Act
2828
provider.Dispose();
2929

test/Microsoft.Extensions.Logging.Test/TraceSourceLoggerTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#if DNX451
4+
#if NET451
55
using System.Diagnostics;
66
using Xunit;
77

test/Microsoft.Extensions.Logging.Test/TraceSourceScopeTest.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace Microsoft.Extensions.Logging.Test
88
{
99
public class TraceSourceScopeTest
1010
{
11-
#if DNX451
11+
#if NET451
1212
[Fact]
1313
public static void DiagnosticsScope_PushesAndPops_LogicalOperationStack()
1414
{
1515
// Arrange
1616
var baseState = "base";
1717
Trace.CorrelationManager.StartLogicalOperation(baseState);
1818
var state = "1337state7331";
19-
19+
2020
var factory = new LoggerFactory();
2121
var logger = factory.CreateLogger("Test");
2222
factory.AddTraceSource(new SourceSwitch("TestSwitch"), new ConsoleTraceListener());

test/Microsoft.Extensions.Logging.Test/project.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
},
55
"dependencies": {
66
"Microsoft.AspNetCore.Testing": "1.0.0-*",
7+
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
78
"Microsoft.Extensions.Logging": "1.0.0-*",
89
"Microsoft.Extensions.Logging.Console": "1.0.0-*",
910
"Microsoft.Extensions.Logging.Debug": "1.0.0-*",
@@ -18,7 +19,8 @@
1819
"portable-net451+win8"
1920
],
2021
"dependencies": {
21-
"Microsoft.NETCore.Platforms": "1.0.1-*",
22+
"NETStandard.Library": "1.5.0-*",
23+
"System.Diagnostics.Process": "4.1.0-*",
2224
"moq.netcore": "4.4.0-beta8",
2325
"dotnet-test-xunit": "1.0.0-dev-*"
2426
}

test/Microsoft.Extensions.Logging.Testing.Tests/project.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"portable-net451+win8"
1616
],
1717
"dependencies": {
18-
"Microsoft.NETCore.Platforms": "1.0.1-*",
18+
"NETStandard.Library": "1.5.0-*",
19+
"System.Diagnostics.Process": "4.1.0-*",
1920
"dotnet-test-xunit": "1.0.0-dev-*"
2021
}
2122
},

0 commit comments

Comments
 (0)