This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more configuration options for logging, add reload
- Loading branch information
Showing
13 changed files
with
505 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"includeScopes" : "false", | ||
"switches": { | ||
"Default": "Verbose", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
{ | ||
"commands": { | ||
"SampleApp": "SampleApp" | ||
"commands": { | ||
"SampleApp": "SampleApp" | ||
}, | ||
"dependencies": { | ||
"Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", | ||
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-*", | ||
"Microsoft.Extensions.Configuration.Json": "1.0.0-*", | ||
"Microsoft.Extensions.Logging": "1.0.0-*", | ||
"Microsoft.Extensions.Logging.Console": "1.0.0-*", | ||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*" | ||
}, | ||
"frameworks": { | ||
"dnx451": { | ||
"dependencies": { | ||
"Microsoft.Extensions.Logging.EventLog": "1.0.0-*", | ||
"Microsoft.Extensions.Logging.NLog": "1.0.0-*" | ||
} | ||
}, | ||
"dependencies": { | ||
"Microsoft.Extensions.Logging": "1.0.0-*", | ||
"Microsoft.Extensions.Logging.Console": "1.0.0-*" | ||
}, | ||
"frameworks": { | ||
"dnx451": { | ||
"dependencies": { | ||
"Microsoft.Extensions.Logging.EventLog": "1.0.0-*", | ||
"Microsoft.Extensions.Logging.NLog": "1.0.0-*" | ||
} | ||
}, | ||
"dnxcore50": { | ||
"dependencies": { | ||
"System.Console": "4.0.0-beta-*" | ||
} | ||
} | ||
"dnxcore50": { | ||
"dependencies": { | ||
"System.Console": "4.0.0-beta-*" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/Microsoft.Extensions.Logging.Console/ConfigurationConsoleLoggerSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 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.Configuration; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace Microsoft.Extensions.Logging.Console | ||
{ | ||
public class ConfigurationConsoleLoggerSettings : IConsoleLoggerSettings | ||
{ | ||
private readonly IConfiguration _configuration; | ||
|
||
public ConfigurationConsoleLoggerSettings(IConfiguration configuration) | ||
{ | ||
_configuration = configuration; | ||
ChangeToken = configuration.GetReloadToken(); | ||
} | ||
|
||
public IChangeToken ChangeToken { get; private set; } | ||
|
||
public bool IncludeScopes | ||
{ | ||
get | ||
{ | ||
bool includeScopes; | ||
var value = _configuration["includeScopes"]; | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
return false; | ||
} | ||
else if (bool.TryParse(value, out includeScopes)) | ||
{ | ||
return includeScopes; | ||
} | ||
else | ||
{ | ||
var message = $"Configuration value '{value}' for setting '{nameof(IncludeScopes)}' is not supported."; | ||
throw new InvalidOperationException(message); | ||
} | ||
} | ||
} | ||
|
||
public IConsoleLoggerSettings Reload() | ||
{ | ||
ChangeToken = null; | ||
return new ConfigurationConsoleLoggerSettings(_configuration); | ||
} | ||
|
||
public bool TryGetSwitch(string name, out LogLevel level) | ||
{ | ||
var switches = _configuration.GetSection("switches"); | ||
if (switches == null) | ||
{ | ||
level = LogLevel.None; | ||
return false; | ||
} | ||
|
||
var value = switches[name]; | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
level = LogLevel.None; | ||
return false; | ||
} | ||
else if (Enum.TryParse<LogLevel>(value, out level)) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
var message = $"Configuration value '{value}' for category '{name}' is not supported."; | ||
throw new InvalidOperationException(message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.