structured logging

This commit is contained in:
Shaun Walker
2019-10-22 11:57:28 -04:00
parent ce25967633
commit 2e3a4efb74
79 changed files with 891 additions and 497 deletions

View File

@ -3,18 +3,22 @@ using Microsoft.AspNetCore.Authorization;
using Oqtane.Modules.HtmlText.Models;
using Oqtane.Modules.HtmlText.Repository;
using Microsoft.AspNetCore.Http;
using Oqtane.Infrastructure;
using Oqtane.Shared;
namespace Oqtane.Modules.HtmlText.Controllers
{
[Route("{site}/api/[controller]")]
public class HtmlTextController : Controller
{
private IHtmlTextRepository htmltext;
private readonly IHtmlTextRepository htmltext;
private readonly ILogManager logger;
private int EntityId = -1; // passed as a querystring parameter for authorization and used for validation
public HtmlTextController(IHtmlTextRepository HtmlText, IHttpContextAccessor HttpContextAccessor)
public HtmlTextController(IHtmlTextRepository HtmlText, ILogManager logger, IHttpContextAccessor HttpContextAccessor)
{
htmltext = HtmlText;
this.logger = logger;
if (HttpContextAccessor.HttpContext.Request.Query.ContainsKey("entityid"))
{
EntityId = int.Parse(HttpContextAccessor.HttpContext.Request.Query["entityid"]);
@ -42,6 +46,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
if (ModelState.IsValid && HtmlText.ModuleId == EntityId)
{
HtmlText = htmltext.AddHtmlText(HtmlText);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Html/Text Added {HtmlText}", HtmlText);
}
return HtmlText;
}
@ -54,6 +59,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
if (ModelState.IsValid && HtmlText.ModuleId == EntityId)
{
HtmlText = htmltext.UpdateHtmlText(HtmlText);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Html/Text Updated {HtmlText}", HtmlText);
}
return HtmlText;
}
@ -66,6 +72,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
if (id == EntityId)
{
htmltext.DeleteHtmlText(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Html/Text Deleted {HtmlTextId}", id);
}
}
}