Skip to content

Commit

Permalink
Merge pull request #48 from serilog/dev
Browse files Browse the repository at this point in the history
1.2.0 Release
  • Loading branch information
nblumhardt authored Aug 8, 2016
2 parents d737c0d + 2f28af4 commit 5e5798a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
1.2.0

* #45 - Make the provider type public so that it can be embedded more easily in other providers

1.1.0

* #41 - Provide a `dispose` flag to instruct provider to take ownership of the Serilog logger

1.0.0

* Initial version

Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@

namespace Serilog.Extensions.Logging
{
class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher
/// <summary>
/// An <see cref="ILoggerProvider"/> that pipes events through Serilog.
/// </summary>
public class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher
{
public const string OriginalFormatPropertyName = "{OriginalFormat}";
internal const string OriginalFormatPropertyName = "{OriginalFormat}";

// May be null; if it is, Log.Logger will be lazily used
readonly ILogger _logger;
readonly Action _dispose;

/// <summary>
/// Construct a <see cref="SerilogLoggerProvider"/>.
/// </summary>
/// <param name="logger">A Serilog logger to pipe events through; if null, the static <see cref="Log"/> class will be used.</param>
/// <param name="dispose">If true, the provided logger or static log class will be disposed/closed when the provider is disposed.</param>
public SerilogLoggerProvider(ILogger logger = null, bool dispose = false)
{
if (logger != null)
Expand All @@ -37,16 +45,19 @@ public SerilogLoggerProvider(ILogger logger = null, bool dispose = false)
}
}

/// <inheritdoc />
public FrameworkLogger CreateLogger(string name)
{
return new SerilogLogger(this, _logger, name);
}

/// <inheritdoc />
public IDisposable BeginScope<T>(T state)
{
return new SerilogLoggerScope(this, state);
}

/// <inheritdoc />
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
for (var scope = CurrentScope; scope != null; scope = scope.Parent)
Expand All @@ -58,7 +69,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
#if ASYNCLOCAL
readonly AsyncLocal<SerilogLoggerScope> _value = new AsyncLocal<SerilogLoggerScope>();

public SerilogLoggerScope CurrentScope
internal SerilogLoggerScope CurrentScope
{
get
{
Expand All @@ -72,7 +83,7 @@ public SerilogLoggerScope CurrentScope
#else
readonly string _currentScopeKey = nameof(SerilogLoggerScope) + "#" + Guid.NewGuid().ToString("n");

public SerilogLoggerScope CurrentScope
internal SerilogLoggerScope CurrentScope
{
get
{
Expand All @@ -86,6 +97,7 @@ public SerilogLoggerScope CurrentScope
}
#endif

/// <inheritdoc />
public void Dispose()
{
_dispose?.Invoke();
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Extensions.Logging/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.0-*",
"version": "1.2.0-*",
"description": "Serilog provider for Microsoft.Extensions.Logging",
"authors": [ "Microsoft", "Serilog Contributors" ],
"packOptions": {
Expand Down

0 comments on commit 5e5798a

Please sign in to comment.