Chd.Library.Logging 9.1.2

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Chd.Library.Logging" Version="9.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chd.Library.Logging --version 9.1.2                
#r "nuget: Chd.Library.Logging, 9.1.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

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

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgements

Thank you for using my library.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
9.1.7 73 1/30/2025
9.1.6 73 1/19/2025
9.1.3 87 1/11/2025
9.1.2 76 1/11/2025
9.1.1 107 1/1/2025
8.0.9 152 12/23/2024
7.4.1 1,028 8/25/2023
7.4.0 590 8/18/2023
1.3.8 472 6/15/2023