Skip to content

Commit af4ddfc

Browse files
committed
Feat: readme and packables
1 parent 6bf2e35 commit af4ddfc

File tree

12 files changed

+452
-8
lines changed

12 files changed

+452
-8
lines changed

assets/icon.png

17.3 KB
Loading

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,32 @@
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
9+
<!-- Main package name -->
10+
<PackageId>CodeOfChaos.Extensions.AspNetCore</PackageId>
11+
<Version>0.20.0-preview.0</Version>
12+
<Authors>Anna Sas</Authors>
13+
<Description>A Library of broadly used extensions for AspNetCore</Description>
14+
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-extensions</PackageProjectUrl>
15+
<PackageTags>extensions AspNetCore</PackageTags>
16+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
17+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
18+
<IncludeSymbols>true</IncludeSymbols>
19+
<DebugType>embedded</DebugType>
20+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
21+
<PackageReadmeFile>README.md</PackageReadmeFile>
22+
<PackageIcon>icon.png</PackageIcon>
823
</PropertyGroup>
924

1025
<ItemGroup>
11-
<PackageReference Include="Serilog" Version="4.2.0" />
12-
<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+
<Content Include="..\..\LICENSE" Link="LICENSE" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
32+
<None Include="README.md" Pack="true" PackagePath="" />
33+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" />
1334
</ItemGroup>
1435

1536
</Project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# CodeOfChaos.Extensions.AspNetCore
2+
3+
`CodeOfChaos.Extensions.AspNetCore` is a lightweight library that simplifies some aspects of ASP.NET Core applications.
4+
5+
---
6+
7+
## Features
8+
9+
### Simplified Serilog Integration
10+
- Easily replaces the default ASP.NET Core logging with **Serilog**.
11+
- Supports **custom configuration** via `LoggerConfiguration` for full control over your logging setup.
12+
- Automatically manages Serilog's lifecycle, ensuring proper cleanup on application shutdown.
13+
14+
---
15+
16+
## Installation
17+
18+
This library targets `.NET 9.0` and requires C# 13.0. Ensure your project meets these requirements before using.
19+
20+
Add the dependency to your project via NuGet:
21+
```bash
22+
dotnet add package CodeOfChaos.Extensions.AspNetCore
23+
```
24+
25+
---
26+
27+
## Usage
28+
29+
Here's how you can use the library to configure Serilog in your ASP.NET Core application:
30+
31+
### Example Setup
32+
1. Install the `CodeOfChaos.Extensions.AspNetCore` package in your project.
33+
2. Modify your `Program.cs` or `Startup.cs` file:
34+
```csharp
35+
using CodeOfChaos.Extensions.AspNetCore;
36+
using Serilog;
37+
38+
var builder = WebApplication.CreateBuilder(args);
39+
40+
// Override logging with Serilog
41+
builder.OverrideLoggingWithSerilog(configure: config =>
42+
{
43+
config.WriteTo.Console(); // Example: Log to console
44+
});
45+
46+
var app = builder.Build();
47+
48+
app.Run();
49+
```
50+
51+
3. Run your application. Serilog will now be the active logging provider.
52+
53+
---
54+
55+
## Features in Detail
56+
57+
### Method: `OverrideLoggingWithSerilog`
58+
This method replaces the default logging system with Serilog. It provides several key capabilities:
59+
- Accepts an **optional configuration delegate** to customize `LoggerConfiguration` (e.g., specifying sinks like Console, File, etc.).
60+
- Integrates all required services and clears default logging providers automatically.
61+
- Ensures proper flushing and cleanup of logs using an internally managed hosted service on application shutdown.
62+
63+
---
64+
65+
## Contributing
66+
67+
Feel free to fork and contribute to the project by submitting pull requests. When contributing, ensure your changes align with the project’s coding standards.

src/CodeOfChaos.Extensions.EntityFrameworkCore/CodeOfChaos.Extensions.EntityFrameworkCore.csproj

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,30 @@
44
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
8+
<!-- Main package name -->
9+
<PackageId>CodeOfChaos.Extensions.EntityFrameworkCore</PackageId>
10+
<Version>0.20.0-preview.0</Version>
11+
<Authors>Anna Sas</Authors>
12+
<Description>A Library of broadly used extensions for EntityFrameworkCore</Description>
13+
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-extensions</PackageProjectUrl>
14+
<PackageTags>extensions linq EntityFrameworkCore</PackageTags>
15+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
16+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
17+
<IncludeSymbols>true</IncludeSymbols>
18+
<DebugType>embedded</DebugType>
19+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
20+
<PackageReadmeFile>README.md</PackageReadmeFile>
21+
<PackageIcon>icon.png</PackageIcon>
722
</PropertyGroup>
823

924
<ItemGroup>
1025
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
1126
</ItemGroup>
12-
27+
28+
<ItemGroup>
29+
<Content Include="..\..\LICENSE" Link="LICENSE" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
30+
<None Include="README.md" Pack="true" PackagePath="" />
31+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" />
32+
</ItemGroup>
1333
</Project>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# CodeOfChaos.Extensions.EntityFrameworkCore
2+
3+
`CodeOfChaos.Extensions.EntityFrameworkCore` is a library that extends LINQ capabilities in Entity Framework Core. It introduces conditional extensions for operations like `Include`, `Where`, `OrderBy`, and others. These methods enable dynamic query building, improving flexibility and readability when working with Entity Framework Core.
4+
5+
---
6+
7+
## Features
8+
9+
### Conditional Query Building
10+
Enhance `IQueryable` queries with conditional functionality:
11+
- **Conditional Includes**:
12+
- Dynamically include related entities based on runtime conditions.
13+
- **Conditional Filters**:
14+
- Apply `Where` clauses only when a condition is met.
15+
- **Conditional Sorting**:
16+
- Apply `OrderBy` clauses conditionally or use optional order expressions.
17+
- **Conditional Pagination**:
18+
- Apply `Take`, including support for ranges.
19+
20+
---
21+
22+
## Installation
23+
24+
This library targets `.NET 9.0` and requires C# 13.0. Ensure your project meets these requirements before using.
25+
26+
Add the dependency to your project via NuGet:
27+
```bash
28+
dotnet add package CodeOfChaos.Extensions.EntityFrameworkCore
29+
```
30+
31+
---
32+
33+
## Usage
34+
35+
Here’s how you can leverage the library for dynamic query building in Entity Framework Core:
36+
37+
### Conditional `Include`
38+
Dynamically include related entities only when needed:
39+
```csharp
40+
using Microsoft.EntityFrameworkCore;
41+
42+
var query = dbContext.Users.ConditionalInclude(isAdmin, u => u.Roles);
43+
```
44+
45+
### Conditional `Where`
46+
Apply a filter based on runtime conditions:
47+
```csharp
48+
var query = dbContext.Users.ConditionalWhere(filterByEmail, u => u.Email == searchEmail);
49+
```
50+
51+
### Conditional `OrderBy`
52+
Use conditional sorting:
53+
```csharp
54+
var query = dbContext.Users.ConditionalOrderBy(applySorting, u => u.LastName);
55+
```
56+
57+
Or, with a comparer:
58+
```csharp
59+
var query = dbContext.Users.ConditionalOrderBy(applySorting, u => u.LastName, StringComparer.OrdinalIgnoreCase);
60+
```
61+
62+
### Conditional `Take`
63+
Limit the results dynamically:
64+
```csharp
65+
var query = dbContext.Users.ConditionalTake(applyPagination, 50);
66+
```
67+
68+
Or, with a range:
69+
```csharp
70+
var query = dbContext.Users.ConditionalTake(applyPagination, ..10);
71+
```
72+
73+
---
74+
75+
## Contributing
76+
77+
Feel free to fork and contribute to the project by submitting pull requests. When contributing, ensure your changes align with the project’s coding standards.

src/CodeOfChaos.Extensions.Serilog/CodeOfChaos.Extensions.Serilog.csproj

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,31 @@
44
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
8+
<!-- Main package name -->
9+
<PackageId>CodeOfChaos.Extensions.Serilog</PackageId>
10+
<Version>0.20.0-preview.0</Version>
11+
<Authors>Anna Sas</Authors>
12+
<Description>A Library of broadly used extensions for Serilog</Description>
13+
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-extensions</PackageProjectUrl>
14+
<PackageTags>extensions Serilog</PackageTags>
15+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
16+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
17+
<IncludeSymbols>true</IncludeSymbols>
18+
<DebugType>embedded</DebugType>
19+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
20+
<PackageReadmeFile>README.md</PackageReadmeFile>
21+
<PackageIcon>icon.png</PackageIcon>
722
</PropertyGroup>
823

924
<ItemGroup>
1025
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
1126
<PackageReference Include="Serilog" Version="4.2.0" />
1227
</ItemGroup>
13-
28+
29+
<ItemGroup>
30+
<Content Include="..\..\LICENSE" Link="LICENSE" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
31+
<None Include="README.md" Pack="true" PackagePath="" />
32+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" />
33+
</ItemGroup>
1434
</Project>

src/CodeOfChaos.Extensions.Serilog/LoggerExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4+
using CodeOfChaos.Extensions.Serilog;
45
using JetBrains.Annotations;
5-
using Serilog;
66
using Serilog.Core;
77
using System.Diagnostics.CodeAnalysis;
88

9-
namespace CodeOfChaos.Extensions.Serilog;
9+
// ReSharper disable once CheckNamespace
10+
namespace Serilog;
1011

1112
// ---------------------------------------------------------------------------------------------------------------------
1213
// Code
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# CodeOfChaos.Extensions.Serilog
2+
3+
`CodeOfChaos.Extensions.Serilog` extends the capabilities of Serilog, providing additional methods to simplify logging and exception management. It is particularly useful for elegantly handling fatal and error conditions, enhancing both logging clarity and application lifecycle management.
4+
5+
---
6+
7+
## Features
8+
9+
### Enhanced Logging and Exception Management
10+
- **Throwable Errors**:
11+
- Log an error and throw an exception in a single call.
12+
- Supports both generic exceptions and custom exception types.
13+
- **Throwable Fatals**:
14+
- Log a fatal error and throw an exception simultaneously.
15+
- Supports both generic and custom exceptions.
16+
- **Exit Logging**:
17+
- Log a fatal error and immediately terminate the application with a specified exit code.
18+
19+
---
20+
21+
## Installation
22+
23+
This library targets `.NET 9.0` and requires C# 13.0. Ensure your project meets these requirements before using.
24+
25+
Add the dependency to your project via NuGet:
26+
```bash
27+
dotnet add package CodeOfChaos.Extensions.Serilog
28+
```
29+
30+
---
31+
32+
## Usage
33+
34+
Here's how you can use the library to enhance logging in your applications:
35+
36+
### Throwable Errors
37+
Log an error and throw an exception:
38+
```csharp
39+
using Serilog;
40+
41+
ILogger logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();
42+
43+
try {
44+
throw logger.ThrowableError("An error occurred: {Error}", "SampleError");
45+
} catch (Exception ex) {
46+
Console.WriteLine($"Caught exception: {ex.Message}");
47+
}
48+
```
49+
50+
Or, use a specific exception type:
51+
```csharp
52+
try {
53+
throw logger.ThrowableError<InvalidOperationException>("Invalid operation: {Details}", "SampleDetails");
54+
} catch (Exception ex) {
55+
Console.WriteLine($"Caught exception: {ex.Message}");
56+
}
57+
```
58+
59+
### Throwable Fatals
60+
Log a fatal error and throw an exception:
61+
```csharp
62+
try {
63+
throw logger.ThrowableFatal("A fatal error occurred: {Error}", "CriticalError");
64+
} catch (Exception ex) {
65+
Console.WriteLine($"Caught fatal exception: {ex.Message}");
66+
}
67+
```
68+
69+
Specify a custom exception type:
70+
```csharp
71+
try {
72+
throw logger.ThrowableFatal<InvalidOperationException>("A critical failure: {Details}", "CriticalDetails");
73+
} catch (Exception ex) {
74+
Console.WriteLine($"Caught fatal exception: {ex.Message}");
75+
}
76+
```
77+
78+
### Exit Logging
79+
Log a fatal error and immediately terminate the application with an exit code:
80+
```csharp
81+
logger.ExitFatal(1, "The application encountered a critical error and will exit: {Reason}", "CriticalIssue");
82+
```
83+
84+
---
85+
86+
## Features in Detail
87+
88+
### Method: `ThrowableError`
89+
- Logs an **error**-level message and throws an exception.
90+
- Supports custom exception types via the generic overload `ThrowableError<TException>()`.
91+
92+
### Method: `ThrowableFatal`
93+
- Logs a **fatal**-level message and throws an exception.
94+
- Supports custom exception types as well.
95+
96+
### Method: `ExitFatal`
97+
- Logs a **fatal**-level message and terminates the application.
98+
- Takes an **exit code** to ensure proper command-line application management.
99+
100+
---
101+
102+
## Contributing
103+
104+
Feel free to fork and contribute to the project by submitting pull requests. When contributing, ensure your changes align with the project’s coding standards.

src/CodeOfChaos.Extensions/CodeOfChaos.Extensions.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
9+
<!-- Main package name -->
10+
<PackageId>CodeOfChaos.Extensions</PackageId>
11+
<Version>0.20.0-preview.0</Version>
12+
<Authors>Anna Sas</Authors>
13+
<Description>A Library of broadly used extensions for dotnet in general</Description>
14+
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-extensions</PackageProjectUrl>
15+
<PackageTags>extensions linq collections string</PackageTags>
16+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
17+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
18+
<IncludeSymbols>true</IncludeSymbols>
19+
<DebugType>embedded</DebugType>
20+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
21+
<PackageReadmeFile>README.md</PackageReadmeFile>
22+
<PackageIcon>icon.png</PackageIcon>
823
</PropertyGroup>
924

25+
<ItemGroup>
26+
<Content Include="..\..\LICENSE" Link="LICENSE" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
27+
<None Include="README.md" Pack="true" PackagePath="" />
28+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" />
29+
</ItemGroup>
30+
1031
</Project>

0 commit comments

Comments
 (0)