-
Notifications
You must be signed in to change notification settings - Fork 103
Adding netstandard 2.0 logging abstraction support #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
07286fc
Ignore JetBrains Rider meta files.
gertjvr 3fa0fcd
Added new extension method to configure serilog from services.
gertjvr b484f37
Update csproj to target netstandard 2.0
gertjvr 62bfb8a
update to dotnet cli 2.0.0-preview2-006497
gertjvr 1b940d7
Single char errors :(
gertjvr 129caf9
Missing package references.
gertjvr 16999cc
Not sure why Microsoft.Extensions.DependencyInjection isn't picked up.
gertjvr 3f86602
Think I figured out what is wrong.
gertjvr 882b821
Removed unneeded extension and updated the version prefix as requested.
gertjvr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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": "1.0.3" | ||
| "version": "2.0.0-preview2-006497" | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
33 changes: 33 additions & 0 deletions
33
src/Serilog.Extensions.Logging/SerilogLoggerServicesExtensions.cs
This file contains hidden or 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,33 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
| using Serilog.Extensions.Logging; | ||
|
|
||
|
|
||
| namespace Serilog | ||
| { | ||
| /// <summary> | ||
| /// Extends <see cref="IServiceCollection"/> with Serilog configuration methods. | ||
| /// </summary> | ||
| public static class SerilogLoggerServicesExtensions | ||
| { | ||
| /// <summary> | ||
| /// Add Serilog to the logging pipeline. | ||
| /// </summary> | ||
| /// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add services to.</param> | ||
| /// <param name="logger">The Serilog logger; if not supplied, the static <see cref="Serilog.Log"/> will be used.</param> | ||
| /// <param name="dispose">When true, dispose <paramref name="logger"/> when the framework disposes the provider. If the | ||
| /// logger is not specified but <paramref name="dispose"/> is true, the <see cref="Log.CloseAndFlush()"/> method will be | ||
| /// called on the static <see cref="Log"/> class instead.</param> | ||
| /// <returns>The logger factory.</returns> | ||
| public static IServiceCollection AddSerilog(this IServiceCollection services, Serilog.ILogger logger = null, bool dispose = false) | ||
| { | ||
| if (services == null) throw new ArgumentNullException(nameof(services)); | ||
|
|
||
| services.AddLogging(builder => builder.AddProvider(new SerilogLoggerProvider(logger, dispose))); | ||
|
|
||
| return services; | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the new world this extension method should go onto
ILoggingBuilderThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pakrym!
@gertjvr I just found the example at: https://github.com/aspnet/Logging/blob/dev/samples/SampleApp/Program.cs#L26
Are you still keen to tinker with this, or should we raise an issue for someone to pick up? Cheers!