Code Monkey home page Code Monkey logo

dblogger.core's Introduction

What is this ?

A full-featured logger to log events into Database to be used in ASP.NET Core 2.x projects

By using this library you will have the following features in your project:

  • Automatically logging all of the errors and events for each request based on LogLevel.
  • Automatically adding a log table to your database.
  • Manually log anything in the application code.
  • Url to see logs, with search and filtering capabilities.
  • ...

Install via NuGet

To install DbLogger.Core, run the following command in the Package Manager Console.

pm> Install-Package DbLogger.Core

You can also view the package page on NuGet.

How to use ?

1- install package from nuget.

2- add required services to Startup class as below :

           services.AddDbLogger(options =>
             {
                 options.logLevel = LogLevel.Error; // Determines whether log statements should be logged 
                 options.Path = "DbLogs";//Specifies the path to view the logs in browser
                 options.ApplicationName = "DbLogger.Core.Example"; //Specifies Application Name To Filter Logs By Applications
             });

3- add middleware to Startup class as below :

   app.UseDbLogger();

4- add following settings to appsettings.json:

    "ConnectionStrings": {
    "DbLoggerConnection": "Server=.;Database=TestDB;Trusted_Connection=True;MultipleActiveResultSets=true",
  }

5- To view list of logs, enter the url defined at step 3 in browser. like : www.site.com/DbLogs

6- after you lunch the app, a table add to your DB that defined by DbLoggerConnection in appsettings.json (AppLogs table).

Important points

  • if you have more than 1 application that uses your Database, you can filter errors by their ApplicationName. so you must determine options.ApplicationName value in all of them.

  • if you need to collect all of your project's Logs in one database, you can set a same connectionString by DbLoggerConnection in their appsettings.json.

  • if you need to customize list and details views and Design your UI, you can override them by Copying items in Views folder into your project and modify them as you need.

  • if you need to manually log something in the application code, so you can use IAppLogService like bellow :

public class HomeController : Controller
   {
       private readonly IAppLogService _appLogService;

       public HomeController(IAppLogService appLogService)
       {
           _appLogService = appLogService;
       }


       public async Task<IActionResult> Index()
       {
           var log = new AppLogInput
           {
               ApplicationName = "DbLogger.Core.Example",
               LogLevel= LogLevel.Information,
               Message="I See Home => Index",
           };
           await _appLogService.CreateAsync(log);

           return View();
       }


   }

Screenshots

alt text

alt text

alt text

dblogger.core's People

Contributors

hamed-shirbandi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dblogger.core's Issues

how can we use our table to store data ?

hi
I recently use this , but I want to insert data into my table Not AppLogInput.cs and AppLogOutput.cs , how can I do that on npm version of LoggerDb not core project ( I can not add core project on my solution)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.