Chd.Library.Logging
9.1.2
See the version list below for details.
dotnet add package Chd.Library.Logging --version 9.1.2
NuGet\Install-Package Chd.Library.Logging -Version 9.1.2
<PackageReference Include="Chd.Library.Logging" Version="9.1.2" />
paket add Chd.Library.Logging --version 9.1.2
#r "nuget: Chd.Library.Logging, 9.1.2"
// Install Chd.Library.Logging as a Cake Addin #addin nuget:?package=Chd.Library.Logging&version=9.1.2 // Install Chd.Library.Logging as a Cake Tool #tool nuget:?package=Chd.Library.Logging&version=9.1.2
Logging library for .Net Core
Chd (cleverly handle difficulty) library helps you cleverly handle difficulty, writing code fastly and do your application stable.
📝 Table of Contents
- About
- Getting Started
- Prerequisites
- Running the tests
- Usage
- Apsettings Configurations
- Authors
- Acknowledgments
🧐 About
Logging is an important feature that finding the cause of problem. This package is very simple to use with aspect oriented programming. This library is sink graylog server. You can see logs on graylog run simple step below.
This library use compile time aspects
🏁 Getting Started
We use "Logged" attribute for logging method.
🛠️ Prerequisites
- You must use .net core 9.0 or higher
- You must execute "NuGet\Install-Package MethodBoundaryAspect.Fody -Version 2.0.150" command on Package Manager Console
- Having graylog server connection information
💉 Injection Logger Into The Project For Logging
Firstly you must call UseLogger method ("app.UseLogger();") in the program.cs file.
var builder = WebApplication.CreateBuilder(args);
....
....
app.UseLogger();
🎈 Usage
You must use Logged attribute on method whice you want to loggging method. Do not forget adding graylog configuration in appsettings.json file. That's it, now you can see the logs of the methods in graylog by using the "logged" attribute in any class you want. You can also see the logs in the directory you specified in the appsettings.json file.
public class LoggingTestController : ControllerBase
{
public LoggingTestController()
{
}
[Logged] //For logging method with parameters and return value.
[Route("Sum")]
[HttpGet]
public int? Sum(int a,int b) //For testing on swagger or etc..
{
return a + b;
}
[Route("Sum")]
[HttpGet]
public int? Multiply(int a,int b) //For testing on swagger or etc..
{
Logger.LogInformation("Some information messages..."); //For manuel logging
return a * b;
}
}
Logging the "Sum" method includes compile-time aspects. Compile-time aspects are faster than run-time aspects because they are woven into the code during the build process, reducing the overhead during execution.
⚙️ Apsettings Configurations
You must add code below in appsettings.json
"LogConfig": {
"Server": "192.168.x.x", //required ip for graylog server
"Port": "xxxx", //graylog server port
"Path": "C:\\Logs\\LibrarySampleApp1\\log.txt",
"PathFormat": "C:\\Logs\\LibrarySampleApp1\\log-{Date}.txt",
"ApplicationName": "Library"
},
Test Result
Test result is shown on graylog UI. You can see running method name and included class name with method parameters value. Enter 4 and 7 values in Sum method using swagger. Then look at the greaylog UI. You should see below logs.
- The LoggingTestController.Sum method started working with "[4,7]" parameters.
- The LoggingTestController.Sum method successfully completed its work by returning the result of 11 with the "[4,7]" input parameters.
If user logged in the application, you can see who user used the application. If method crashed you can see why the method crashed. Sometime method crashed for some invalid parameters. You can calculate error reason.
⛏️ Built Using
- Graylog - Graylog server
✍️ Authors
- Mehmet Yoldaş - Linkedin
See also the list of contributors who participated in this project.
🎉 Acknowledgements
Thank you for using my library.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Chd.Library.Common (>= 9.0.8)
- MethodBoundaryAspect.Fody (>= 2.0.150)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.RazorPages (>= 2.2.5)
- Microsoft.AspNetCore.Mvc.ViewFeatures (>= 2.2.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 8.0.0)
- Microsoft.Extensions.Configuration.Json (>= 8.0.0)
- Microsoft.Extensions.Hosting (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Serilog (>= 3.1.1)
- Serilog.Enrichers.Environment (>= 2.3.0)
- Serilog.Settings.Configuration (>= 8.0.0)
- Serilog.Sinks.File (>= 5.0.0)
- Serilog.Sinks.Graylog (>= 3.1.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Chd.Library.Logging:
Package | Downloads |
---|---|
Chd.Library.Core
The library written for .net core framework |
|
Chd.Library.Web.Socket
The library written for .net core framework |
|
Chd.Library.MQTT
The library written for .net core framework |
GitHub repositories
This package is not used by any popular GitHub repositories.