Skip to content

Commit 2ef7643

Browse files
committed
Feat: LoggingFactoryExtensions
1 parent 1fca49b commit 2ef7643

File tree

46 files changed

+310
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+310
-240
lines changed

.editorconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ dotnet_naming_symbols.private_instance_fields_symbols.resharper_applicable_kinds
7171
dotnet_naming_symbols.private_instance_fields_symbols.resharper_required_modifiers = instance
7272
dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_accessibilities = private
7373
dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_kinds = field
74-
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_applicable_kinds = field,readonly_field
74+
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_applicable_kinds = field, readonly_field
7575
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_required_modifiers = instance
7676
dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private
7777
dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field
@@ -84,11 +84,11 @@ dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = reado
8484
dotnet_naming_symbols.private_static_readonly_symbols.resharper_applicable_kinds = readonly_field
8585
dotnet_naming_symbols.private_static_readonly_symbols.resharper_required_modifiers = static
8686
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
87-
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
87+
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
8888
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
8989
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
9090
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities = *
91-
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
91+
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
9292
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field
9393
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance
9494
dotnet_sort_system_directives_first = false
@@ -143,7 +143,7 @@ resharper_formatter_tags_enabled = true
143143
resharper_indent_preprocessor_if = usual_indent
144144
resharper_indent_preprocessor_other = do_not_change
145145
resharper_indent_raw_literal_string = indent
146-
resharper_instance_members_qualify_declared_in =
146+
resharper_instance_members_qualify_declared_in =
147147
resharper_keep_existing_attribute_arrangement = true
148148
resharper_keep_existing_declaration_block_arrangement = true
149149
resharper_keep_existing_embedded_block_arrangement = true

examples/Examples.CodeOfChaos.Extensions.Analyzers/Examples.CodeOfChaos.Extensions.Analyzers.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<ProjectReference Include="..\..\src\CodeOfChaos.Extensions.Analyzers\CodeOfChaos.Extensions.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
10-
<ProjectReference Include="..\..\src\CodeOfChaos.Extensions\CodeOfChaos.Extensions.csproj" />
9+
<ProjectReference Include="..\..\src\CodeOfChaos.Extensions.Analyzers\CodeOfChaos.Extensions.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
10+
<ProjectReference Include="..\..\src\CodeOfChaos.Extensions\CodeOfChaos.Extensions.csproj"/>
1111
</ItemGroup>
1212

1313
</Project>

examples/Examples.CodeOfChaos.Extensions.Analyzers/ToGuidDiagnostic.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
using System;
55

66
namespace Examples.CodeOfChaos.Extensions.Analyzers;
7-
87
// ---------------------------------------------------------------------------------------------------------------------
98
// Code
109
// ---------------------------------------------------------------------------------------------------------------------
1110
public class ToGuidDiagnostic {
12-
public Guid Something() {
13-
return "b60fbc5b-86eb-472b-bfc6-0439d9a70e94".ToGuid();
14-
}
15-
public Guid SomethingWrong() {
16-
return "alpha".ToGuid();
17-
}
11+
public Guid Something() => "b60fbc5b-86eb-472b-bfc6-0439d9a70e94".ToGuid();
12+
public Guid SomethingWrong() => "alpha".ToGuid();
1813
}

src/CodeOfChaos.Extensions.Analyzers/AnalyzerReleases.Shipped.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
### New Rules
44

5-
Rule ID | Category | Severity | Notes
6-
--------|----------|----------|------------------------
7-
CODE001 | Usage | Warning | GuidValidationAnalyzer
5+
Rule ID | Category | Severity | Notes
6+
---------|----------|----------|------------------------
7+
CODE001 | Usage | Warning | GuidValidationAnalyzer
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
### New Rules
22

3-
Rule ID | Category | Severity | Notes
4-
--------|----------|----------|-------
3+
Rule ID | Category | Severity | Notes
4+
---------|----------|----------|-------

src/CodeOfChaos.Extensions.Analyzers/CodeOfChaos.Extensions.Analyzers.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageReadmeFile>README.md</PackageReadmeFile>
2626
<PackageIcon>icon.png</PackageIcon>
2727
</PropertyGroup>
28-
28+
2929
<ItemGroup>
3030
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
3131
<PrivateAssets>all</PrivateAssets>
@@ -40,13 +40,13 @@
4040
</ItemGroup>
4141

4242
<ItemGroup>
43-
<None Include="..\..\LICENSE" Pack="true" PackagePath="" Visible="false" />
44-
<None Include="README.md" Pack="true" PackagePath="" />
45-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
43+
<None Include="..\..\LICENSE" Pack="true" PackagePath="" Visible="false"/>
44+
<None Include="README.md" Pack="true" PackagePath=""/>
45+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
4646
</ItemGroup>
47-
47+
4848
<ItemGroup>
49-
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
49+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
5050
</ItemGroup>
5151

5252
</Project>

src/CodeOfChaos.Extensions.Analyzers/GuidValidationAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) {
4747
return;
4848

4949
string guidString = literalExpression.Token.ValueText;
50-
if (Guid.TryParse(guidString, out _)) return; // If the string is a valid GUID, we don't need to report a diagnostic.
50+
if (Guid.TryParse(guidString, out _)) return;// If the string is a valid GUID, we don't need to report a diagnostic.
5151

5252
var diagnostic = Diagnostic.Create(Rule, literalExpression.GetLocation(), guidString);
5353
context.ReportDiagnostic(diagnostic);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# CodeOfChaos.Extensions.Analyzers
2+
23
Additional diagnostics to make CodeOfChaos.Extensions easier to use as a developer

src/CodeOfChaos.Extensions.AspNetCore/CodeOfChaos.Extensions.AspNetCore.csproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
8+
99
<!-- Main package name -->
1010
<PackageId>CodeOfChaos.Extensions.AspNetCore</PackageId>
1111
<Version>0.24.3</Version>
@@ -23,14 +23,18 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="Serilog" Version="4.2.0" />
27-
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
26+
<PackageReference Include="Serilog" Version="4.2.0"/>
27+
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0"/>
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<None Include="..\..\LICENSE" Pack="true" PackagePath="" Visible="false"/>
32+
<None Include="README.md" Pack="true" PackagePath=""/>
33+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
2834
</ItemGroup>
2935

3036
<ItemGroup>
31-
<None Include="..\..\LICENSE" Pack="true" PackagePath="" Visible="false" />
32-
<None Include="README.md" Pack="true" PackagePath="" />
33-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
37+
<ProjectReference Include="..\CodeOfChaos.Extensions.Serilog\CodeOfChaos.Extensions.Serilog.csproj"/>
3438
</ItemGroup>
3539

3640
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.Extensions.Logging;
5+
using Serilog;
6+
7+
namespace CodeOfChaos.Extensions.AspNetCore;
8+
// ---------------------------------------------------------------------------------------------------------------------
9+
// Code
10+
// ---------------------------------------------------------------------------------------------------------------------
11+
/// <summary>
12+
/// Provides extension methods for creating and configuring <see cref="ILoggerFactory" /> instances with Serilog.
13+
/// </summary>
14+
public static class LoggingFactoryExtensions {
15+
/// <summary>
16+
/// Creates an <see cref="ILoggerFactory" /> configured to use Serilog as the logging provider.
17+
/// </summary>
18+
/// <returns>An instance of <see cref="ILoggerFactory" /> configured with Serilog.</returns>
19+
public static ILoggerFactory CreateWithSerilog()
20+
=> LoggerFactory.Create(builder => builder.AddSerilog(Log.Logger));
21+
/// <summary>
22+
/// Creates a new instance of <see cref="ILoggerFactory" /> configured with Serilog.
23+
/// </summary>
24+
/// <returns>A configured <see cref="ILoggerFactory" /> instance.</returns>
25+
public static ILoggerFactory CreateWithSerilog(string sectionName)
26+
=> LoggerFactory.Create(builder => builder.AddSerilog(Log.Logger.ForSectionProperty(sectionName)));
27+
}

0 commit comments

Comments
 (0)