Skip to content

glosse13/.NetCore_ElasticSearchv7_LogEverything

 
 

Repository files navigation

Screenshot

.Net Core - Elastic Search Log Everything

Build Status Coverage Status License Issiue

It is a library where you can log all the movements that occur in your application.

Specifications

  • Specific Logging. Create Index and Log Your Model.
  • Catches Database Changing (Update,Delete) and Logs with Current User Id.
  • Logs Selected Endpoints with Ip Address, Query or Body Params and Current User Id.
  • Catches All Exception in Project and Logs with Exception Message, Status Code and Current User Id.
  • Elastic Search Management Service Class. Index Management, Alias Management, Search Logs.

Dependencies

  • Net Core 3
  • NEST Library
  • Entity Framework

Links

Screenshots

Activity Log Entitiy Changes Log
Screenshot Screenshot
Error Log Elastic Search Management
Screenshot Screenshot

Service Settings

Startup.cs

 public void ConfigureServices(IServiceCollection services)
 {
   services.AddElasticServices();
 }

appsettings.json

  "ElasticConnectionSettings": {
    "ConnectionString": {
      "HostUrls": "http://localhost:9200/",
      "UserName": "",
      "Password": ""
    }
  }

EndPoint Activity Logging (Controller/Action)

[ActivityFilter(LogAllEndPoints: false)] // -> Add Filter To Your Controller
[LogEndpoint] // if LogAllEndPoints:false -> Use [LogEndpoint] for logging specific endpoints.
[NoLogEndpoint] // if LogAllEndPoints:true -> Use [NoLogEndpoint] for remove logging to specific endpoints.


Database Entities Logging

Entity Context Class

 public override int SaveChanges() 
 {
      dbLogger.LogChanges(ChangeTracker);
      return base.SaveChanges();
 }

Entity Model Class

 [LogModel]  // ->  Logs All Props
 public class Product
 {
     [DisplayName("Record Id")] // For clarity when displaying Entity Log records
     public int ID { get; set; }
     [LogProp]  // -> Log Specific Props (Remove LogModel Attribute)
     public string Name { get; set; }
     [DisplayName("Seri No")]
     [LogProp]
     public string SeriNo { get; set; }
 }

Error Logging (Startup.cs)


 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 {
   app.AddElasticErrorHandler();
 }


Elastic Management Controller


  public class ElasticController : ElasticSearchController
  {
      public ElasticController(IElasticSearchManager _elasticSearchService) : base(_elasticSearchService) { }
  }


License

License

About

.Net Core 3 and Elastic Search v5-v6-v7 Logging

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%