generated from dailydevops/template-dotnet
-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Added Logging
#21
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
+166
−1
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
115 changes: 115 additions & 0 deletions
115
src/NetEvolve.ForgingBlazor.Logging/ApplicationBuilderExtensions.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,115 @@ | ||
| namespace NetEvolve.ForgingBlazor.Logging; | ||
|
|
||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
| using NetEvolve.ForgingBlazor.Extensibility.Abstractions; | ||
|
|
||
| /// <summary> | ||
| /// Provides extension methods for <see cref="IApplicationBuilder"/> to configure and integrate logging services | ||
| /// into the Forging Blazor application pipeline. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This class offers a fluent API for adding logging capabilities to applications built with the Forging Blazor framework. | ||
| /// It provides both pre-configured default logging setups and flexible custom configurations to meet various logging requirements. | ||
| /// </remarks> | ||
| public static class ApplicationBuilderExtensions | ||
| { | ||
| /// <summary> | ||
| /// Configures the application with default logging providers, including console and debug output. | ||
| /// </summary> | ||
| /// <param name="builder"> | ||
| /// The <see cref="IApplicationBuilder"/> instance that represents the application being configured. | ||
| /// This parameter serves as the entry point for adding logging services to the application's service collection. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The same <see cref="IApplicationBuilder"/> instance that was passed in, enabling method chaining | ||
| /// and fluent configuration of additional application features. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// Thrown when <paramref name="builder"/> is <see langword="null"/>. | ||
| /// </exception> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// This method provides a convenient way to quickly set up logging with sensible defaults. | ||
| /// It automatically configures both console and debug logging providers, which are suitable | ||
| /// for most development and debugging scenarios. | ||
| /// </para> | ||
| /// <para> | ||
| /// The console provider outputs log messages to the standard console output, while the debug provider | ||
| /// writes to the debug output window in development environments and attached debuggers. | ||
| /// </para> | ||
| /// <para> | ||
| /// For production scenarios or when specific logging providers are required, consider using the | ||
| /// overload that accepts an <see cref="Action{ILoggingBuilder}"/> delegate for custom configuration. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <example> | ||
| /// <code> | ||
| /// var builder = ApplicationBuilder.Create(); | ||
| /// builder.WithLogging(); | ||
| /// </code> | ||
| /// </example> | ||
| /// <seealso cref="WithLogging(IApplicationBuilder, Action{ILoggingBuilder})"/> | ||
| public static IApplicationBuilder WithLogging(this IApplicationBuilder builder) => | ||
| builder.WithLogging(configure => configure.AddConsole().AddDebug()); | ||
|
|
||
| /// <summary> | ||
| /// Configures the application with custom logging providers using a flexible configuration delegate. | ||
| /// </summary> | ||
| /// <param name="builder"> | ||
| /// The <see cref="IApplicationBuilder"/> instance that represents the application being configured. | ||
| /// This parameter serves as the entry point for adding logging services to the application's service collection. | ||
| /// </param> | ||
| /// <param name="configure"> | ||
| /// An <see cref="Action{ILoggingBuilder}"/> delegate that provides fine-grained control over the logging configuration. | ||
| /// This delegate receives an <see cref="ILoggingBuilder"/> instance that can be used to add logging providers, | ||
| /// set minimum log levels, add filters, and perform other logging-related configurations. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The same <see cref="IApplicationBuilder"/> instance that was passed in, enabling method chaining | ||
| /// and fluent configuration of additional application features. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// Thrown when <paramref name="builder"/> is <see langword="null"/>. | ||
| /// </exception> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// This method offers maximum flexibility for configuring logging in the Forging Blazor application. | ||
| /// It allows developers to choose specific logging providers, configure log levels, add custom filters, | ||
| /// and integrate third-party logging frameworks according to their application's requirements. | ||
| /// </para> | ||
| /// <para> | ||
| /// The configuration delegate is executed immediately during the application builder's configuration phase, | ||
| /// ensuring that logging services are properly registered before any application components attempt to use them. | ||
| /// </para> | ||
| /// <para> | ||
| /// Common use cases include integrating structured logging providers (such as Serilog or NLog), | ||
| /// configuring cloud-based logging services (like Application Insights or AWS CloudWatch), | ||
| /// or setting up custom logging filters for performance optimization. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <example> | ||
| /// <para>Example with custom log levels and multiple providers:</para> | ||
| /// <code> | ||
| /// var builder = ApplicationBuilder.Create(); | ||
| /// builder.WithLogging(logging => | ||
| /// { | ||
| /// logging.SetMinimumLevel(LogLevel.Information); | ||
| /// logging.AddConsole(); | ||
| /// logging.AddEventLog(); | ||
| /// logging.AddFilter("Microsoft", LogLevel.Warning); | ||
| /// }); | ||
| /// </code> | ||
| /// </example> | ||
| /// <seealso cref="WithLogging(IApplicationBuilder)"/> | ||
| /// <seealso cref="ILoggingBuilder"/> | ||
| /// <seealso cref="LoggingServiceCollectionExtensions.AddLogging(IServiceCollection, Action{ILoggingBuilder})"/> | ||
| public static IApplicationBuilder WithLogging(this IApplicationBuilder builder, Action<ILoggingBuilder> configure) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
|
|
||
| _ = builder.Services.AddLogging(configure); | ||
|
|
||
| return builder; | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/NetEvolve.ForgingBlazor.Logging/NetEvolve.ForgingBlazor.Logging.csproj
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,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>$(_ProjectTargetFrameworks)</TargetFrameworks> | ||
| <PackageTags>$(PackageTags);logging</PackageTags> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Logging" /> | ||
| <PackageReference Include="Microsoft.Extensions.Logging.Console" /> | ||
| <PackageReference Include="YamlDotNet" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="NetEvolve.ForgingBlazor" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\NetEvolve.ForgingBlazor.Extensibility\NetEvolve.ForgingBlazor.Extensibility.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
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
12 changes: 12 additions & 0 deletions
12
src/NetEvolve.ForgingBlazor/ServiceCollectionExtensions.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,12 @@ | ||
| namespace NetEvolve.ForgingBlazor; | ||
|
|
||
| using System.CommandLine; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using NetEvolve.ForgingBlazor.Commands; | ||
| using NetEvolve.ForgingBlazor.Extensibility.Abstractions; | ||
|
|
||
| internal static class ServiceCollectionExtensions | ||
| { | ||
| internal static bool IsServiceTypeRegistered<T>(this IServiceCollection builder) | ||
| where T : class => builder.Any(x => x.ServiceType == typeof(T)); | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.