Step 3. Create the class file under an “Interface” folder, then setting the “ILogRepository.”
namespace Enterprise_Dot_Net_Core_WebApp.Logging.Interface
{
public interface ILogRepository
{
}
} Step 4. Create the class file under a “Repository” folder, then set the “LogRepository.” Add the action filter source code in the LogRepository file.
public override void OnActionExecuting(ActionExecutingContext context)
{
_logger.LogInformation("ClassFilter OnActionExecuting");
base.OnActionExecuting(context);
}
public override void OnActionExecuted(ActionExecutedContext context)
{
_logger.LogInformation("ClassFilter OnActionExecuted");
base.OnActionExecuted(context);
}
public override void OnResultExecuting(ResultExecutingContext context)
{
_logger.LogInformation("ClassFilter OnResultExecuting");
if (context.Result != null)
{
var resultMsg = context.Result;
if (resultMsg is JsonResult json)
{
_logger.LogInformation("JSON Serializer Setting: " + json.SerializerSettings);
_logger.LogInformation("JSON Content Type: " + json.ContentType);
_logger.LogInformation("JSON Status Code: " + json.StatusCode);
_logger.LogInformation("JSON Value: " + JsonConvert.SerializeObject(json.Value));
}
if (resultMsg is ViewResult view)
{
_logger.LogInformation("View Name: " + view.ViewName);
_logger.LogInformation("View Status: " + view.StatusCode);
_logger.LogInformation("View ContentTpye:" + view.ContentType);
_logger.LogInformation("View Data: " + JsonConvert.SerializeObject(view.ViewData));
_logger.LogInformation("View Data Model: " + JsonConvert.SerializeObject(view.ViewData.Model));
_logger.LogInformation("Temp Data: " + JsonConvert.SerializeObject(view.TempData));
}
}
base.OnResultExecuting(context);
}
public override void OnResultExecuted(ResultExecutedContext context)
{
_logger.LogInformation("ClassFilter OnResultExecuted");
base.OnResultExecuted(context);
} Step 5. Install Serilog.Extensions.Logging.File NuGet package by NuGet management platform in Visual Studio 2017.
The single-responsibility principle (SRP) is a computer-programming principle that states that every module, class or…
Command query responsibility segregation (CQRS) generalizes CQS to message-driven and event-driven architectures: it applies the CQS…
Domain-driven design (DDD) is a software design approach focusing on modelling software to match a…
A microservice architecture – a variant of the service-oriented architecture (SOA) structural style – arranges…
The Repository pattern and Unit of Work pattern are used together in most time. Unit…
Visitor – It allows the program changes the algorithm and the operations that base on the visitor…
View Comments