-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from serilog/dev
3.0.0 Release
- Loading branch information
Showing
25 changed files
with
754 additions
and
222 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
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,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "2.0.0-preview2-006497" | ||
"version": "2.2.103" | ||
} | ||
} |
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
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,11 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=destructure/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=destructured/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Destructurer/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Destructures/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=enricher/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=enrichers/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Loggable/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nonscalar/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Serilog/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=sobj/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
81 changes: 81 additions & 0 deletions
81
src/Serilog.Extensions.Logging/Extensions/Logging/LevelConvert.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,81 @@ | ||
// Copyright 2019 Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Serilog.Events; | ||
|
||
// ReSharper disable RedundantCaseLabel | ||
|
||
namespace Serilog.Extensions.Logging | ||
{ | ||
/// <summary> | ||
/// Converts between Serilog and Microsoft.Extensions.Logging level enum values. | ||
/// </summary> | ||
public static class LevelConvert | ||
{ | ||
/// <summary> | ||
/// Convert <paramref name="logLevel"/> to the equivalent Serilog <see cref="LogEventLevel"/>. | ||
/// </summary> | ||
/// <param name="logLevel">A Microsoft.Extensions.Logging <see cref="LogLevel"/>.</param> | ||
/// <returns>The Serilog equivalent of <paramref name="logLevel"/>.</returns> | ||
/// <remarks>The <see cref="LogLevel.None"/> value has no Serilog equivalent. It is mapped to | ||
/// <see cref="LogEventLevel.Fatal"/> as the closest approximation, but this has entirely | ||
/// different semantics.</remarks> | ||
public static LogEventLevel ToSerilogLevel(LogLevel logLevel) | ||
{ | ||
switch (logLevel) | ||
{ | ||
case LogLevel.None: | ||
case LogLevel.Critical: | ||
return LogEventLevel.Fatal; | ||
case LogLevel.Error: | ||
return LogEventLevel.Error; | ||
case LogLevel.Warning: | ||
return LogEventLevel.Warning; | ||
case LogLevel.Information: | ||
return LogEventLevel.Information; | ||
case LogLevel.Debug: | ||
return LogEventLevel.Debug; | ||
case LogLevel.Trace: | ||
default: | ||
return LogEventLevel.Verbose; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Convert <paramref name="logEventLevel"/> to the equivalent Microsoft.Extensions.Logging <see cref="LogLevel"/>. | ||
/// </summary> | ||
/// <param name="logEventLevel">A Serilog <see cref="LogEventLevel"/>.</param> | ||
/// <returns>The Microsoft.Extensions.Logging equivalent of <paramref name="logEventLevel"/>.</returns> | ||
public static LogLevel ToExtensionsLevel(LogEventLevel logEventLevel) | ||
{ | ||
switch (logEventLevel) | ||
{ | ||
case LogEventLevel.Fatal: | ||
return LogLevel.Critical; | ||
case LogEventLevel.Error: | ||
return LogLevel.Error; | ||
case LogEventLevel.Warning: | ||
return LogLevel.Warning; | ||
case LogEventLevel.Information: | ||
return LogLevel.Information; | ||
case LogEventLevel.Debug: | ||
return LogLevel.Debug; | ||
case LogEventLevel.Verbose: | ||
default: | ||
return LogLevel.Trace; | ||
} | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/Serilog.Extensions.Logging/Extensions/Logging/LoggerProviderCollection.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,67 @@ | ||
// Copyright 2019 Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Serilog.Extensions.Logging | ||
{ | ||
/// <summary> | ||
/// A dynamically-modifiable collection of <see cref="ILoggerProvider"/>s. | ||
/// </summary> | ||
public class LoggerProviderCollection : IDisposable | ||
{ | ||
volatile ILoggerProvider[] _providers = new ILoggerProvider[0]; | ||
|
||
/// <summary> | ||
/// Add <paramref name="provider"/> to the collection. | ||
/// </summary> | ||
/// <param name="provider">A logger provider.</param> | ||
public void AddProvider(ILoggerProvider provider) | ||
{ | ||
if (provider == null) throw new ArgumentNullException(nameof(provider)); | ||
|
||
var existing = _providers; | ||
var added = existing.Concat(new[] {provider}).ToArray(); | ||
|
||
#pragma warning disable 420 // ref to a volatile field | ||
while (Interlocked.CompareExchange(ref _providers, added, existing) != existing) | ||
#pragma warning restore 420 | ||
{ | ||
existing = _providers; | ||
added = existing.Concat(new[] { provider }).ToArray(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get the currently-active providers. | ||
/// </summary> | ||
/// <remarks> | ||
/// If the collection has been disposed, we'll leave the individual | ||
/// providers with the job of throwing <see cref="ObjectDisposedException"/>. | ||
/// </remarks> | ||
public IEnumerable<ILoggerProvider> Providers => _providers; | ||
|
||
/// <inheritdoc cref="IDisposable"/> | ||
public void Dispose() | ||
{ | ||
foreach (var provider in _providers) | ||
provider.Dispose(); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/Serilog.Extensions.Logging/Extensions/Logging/LoggerProviderCollectionSink.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,62 @@ | ||
// Copyright 2019 Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Extensions.Logging | ||
{ | ||
class LoggerProviderCollectionSink : ILogEventSink, IDisposable | ||
{ | ||
readonly LoggerProviderCollection _providers; | ||
|
||
public LoggerProviderCollectionSink(LoggerProviderCollection providers) | ||
{ | ||
_providers = providers ?? throw new ArgumentNullException(nameof(providers)); | ||
} | ||
|
||
public void Emit(LogEvent logEvent) | ||
{ | ||
string categoryName = null; | ||
|
||
if (logEvent.Properties.TryGetValue("SourceContext", out var sourceContextProperty) && | ||
sourceContextProperty is ScalarValue sourceContextValue && | ||
sourceContextValue.Value is string sourceContext) | ||
{ | ||
categoryName = sourceContext; | ||
} | ||
|
||
var level = LevelConvert.ToExtensionsLevel(logEvent.Level); | ||
var slv = new SerilogLogValues(logEvent.MessageTemplate, logEvent.Properties); | ||
|
||
foreach (var provider in _providers.Providers) | ||
{ | ||
var logger = provider.CreateLogger(categoryName); | ||
|
||
logger.Log( | ||
level, | ||
default, | ||
slv, | ||
logEvent.Exception, | ||
(s, e) => s.ToString()); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_providers.Dispose(); | ||
} | ||
} | ||
} |
Oops, something went wrong.