CodeOfChaos.Extensions.Serilog
0.23.1
See the version list below for details.
dotnet add package CodeOfChaos.Extensions.Serilog --version 0.23.1
NuGet\Install-Package CodeOfChaos.Extensions.Serilog -Version 0.23.1
<PackageReference Include="CodeOfChaos.Extensions.Serilog" Version="0.23.1" />
paket add CodeOfChaos.Extensions.Serilog --version 0.23.1
#r "nuget: CodeOfChaos.Extensions.Serilog, 0.23.1"
// Install CodeOfChaos.Extensions.Serilog as a Cake Addin #addin nuget:?package=CodeOfChaos.Extensions.Serilog&version=0.23.1 // Install CodeOfChaos.Extensions.Serilog as a Cake Tool #tool nuget:?package=CodeOfChaos.Extensions.Serilog&version=0.23.1
CodeOfChaos.Extensions.Serilog
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.
Features
Enhanced Logging and Exception Management
- Throwable Errors:
- Log an error and throw an exception in a single call.
- Supports both generic exceptions and custom exception types.
- Throwable Fatals:
- Log a fatal error and throw an exception simultaneously.
- Supports both generic and custom exceptions.
- Exit Logging:
- Log a fatal error and immediately terminate the application with a specified exit code.
Installation
This library targets .NET 9.0
and requires C# 13.0. Ensure your project meets these requirements before using.
Add the dependency to your project via NuGet:
dotnet add package CodeOfChaos.Extensions.Serilog
Usage
Here's how you can use the library to enhance logging in your applications:
Throwable Errors
Log an error and throw an exception:
using Serilog;
ILogger logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();
try {
throw logger.ThrowableError("An error occurred: {Error}", "SampleError");
} catch (Exception ex) {
Console.WriteLine($"Caught exception: {ex.Message}");
}
Or, use a specific exception type:
try {
throw logger.ThrowableError<InvalidOperationException>("Invalid operation: {Details}", "SampleDetails");
} catch (Exception ex) {
Console.WriteLine($"Caught exception: {ex.Message}");
}
Throwable Fatals
Log a fatal error and throw an exception:
try {
throw logger.ThrowableFatal("A fatal error occurred: {Error}", "CriticalError");
} catch (Exception ex) {
Console.WriteLine($"Caught fatal exception: {ex.Message}");
}
Specify a custom exception type:
try {
throw logger.ThrowableFatal<InvalidOperationException>("A critical failure: {Details}", "CriticalDetails");
} catch (Exception ex) {
Console.WriteLine($"Caught fatal exception: {ex.Message}");
}
Exit Logging
Log a fatal error and immediately terminate the application with an exit code:
logger.ExitFatal(1, "The application encountered a critical error and will exit: {Reason}", "CriticalIssue");
Features in Detail
Method: ThrowableError
- Logs an error-level message and throws an exception.
- Supports custom exception types via the generic overload
ThrowableError<TException>()
.
Method: ThrowableFatal
- Logs a fatal-level message and throws an exception.
- Supports custom exception types as well.
Method: ExitFatal
- Logs a fatal-level message and terminates the application.
- Takes an exit code to ensure proper command-line application management.
Contributing
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.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- CodeOfChaos.Ansi (>= 0.1.7)
- JetBrains.Annotations (>= 2024.3.0)
- Serilog (>= 4.2.0)
- Serilog.Sinks.Async (>= 2.1.0)
- Serilog.Sinks.Console (>= 6.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CodeOfChaos.Extensions.Serilog:
Package | Downloads |
---|---|
CodeOfChaos.AspNetCore
A Library of Nuget Packages frequently used in other code-of-chaos projects or project written by Andreas |
|
CodeOfChaos.Extensions.AspNetCore
A Library of broadly used extensions for AspNetCore |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.27.0 | 45 | 12/29/2024 |
0.26.0 | 53 | 12/28/2024 |
0.25.0 | 48 | 12/28/2024 |
0.24.3 | 47 | 12/27/2024 |
0.24.2 | 38 | 12/27/2024 |
0.24.1 | 37 | 12/27/2024 |
0.24.0 | 38 | 12/27/2024 |
0.23.1 | 39 | 12/27/2024 |
0.23.0 | 40 | 12/27/2024 |
0.22.2 | 44 | 12/27/2024 |
0.22.0 | 76 | 12/23/2024 |
0.21.0 | 86 | 12/22/2024 |
0.20.0-preview.1 | 44 | 12/21/2024 |
0.4.1 | 107 | 10/31/2024 |
0.4.0 | 158 | 9/4/2024 |
0.3.1 | 139 | 8/30/2024 |
0.3.0 | 181 | 7/8/2024 |
0.2.3 | 119 | 7/8/2024 |
0.2.2 | 121 | 7/6/2024 |
0.2.1 | 131 | 7/1/2024 |
0.2.0 | 268 | 6/8/2024 |
0.1.0 | 191 | 6/7/2024 |