It is a library where you can log all the movements that occur in your application.
- 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.
- Net Core 3
- NEST Library
- Entity Framework
Activity Log | Entitiy Changes Log |
---|---|
Error Log | Elastic Search Management |
---|---|
Install-Package ElasticSearchLibrary
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddElasticServices();
}
appsettings.json
"ElasticConnectionSettings": {
"ConnectionString": {
"HostUrls": "http://localhost:9200/",
"UserName": "",
"Password": ""
}
}
[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.
Entity Context Class
private IDatabaseLogger dbLogger;
public ProductContext(DbContextOptions options, IDatabaseLogger _dbLogger) : base(options)
{
this.dbLogger = _dbLogger;
}
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; }
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.AddElasticErrorHandler();
}
public class ElasticController : ElasticSearchController
{
public ElasticController(IElasticSearchManager _elasticSearchService) : base(_elasticSearchService) { }
}
- MIT license
- Copyright 2020 ©
Medium TR : https://hasansahinn.medium.com/asp-net-core-3-elastic-search-log-everything-3d567bed2c00