- App Logger entfernt und durch die Implementierung des `ILogger`-Interfaces ersetzt, um eine konsistente Logging-Architektur zu gewährleisten. - API für die Nutzung von NLog konfiguriert, um eine leistungsstarke und flexible Logging-Lösung bereitzustellen. - Konfigurationsdateien und Setup-Anpassungen für die Integration von NLog in die API vorgenommen.
56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using HRD.WebApi.DAL;
|
|
using HRD.WebApi.Helpers;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
|
|
namespace HRD.WebApi.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[Produces("application/json")]
|
|
[ApiController]
|
|
public abstract class InfoBaseController : BaseMiniController
|
|
{
|
|
public InfoBaseController(WebApiBaseContext webApiBaseContext, ILogger<InfoBaseController> logger) : base(webApiBaseContext, logger)
|
|
{
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult<ServerInfo> GetInfos()
|
|
{
|
|
try
|
|
{
|
|
var serverInfo = GetServerInfo();
|
|
return StatusCode(serverInfo.Status, serverInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "{entityMessage}", ex.Message);
|
|
return NotFound();
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult<ServerInfo> GetInfos([FromBody] ServerInfo serverInfoFromClient)
|
|
{
|
|
try
|
|
{
|
|
var serverInfo = GetServerInfo();
|
|
serverInfo.LastOfflineTime = serverInfoFromClient.LastOfflineTime;
|
|
|
|
return new OkObjectResult(serverInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WriteLogException(ex);
|
|
return NotFound();
|
|
}
|
|
}
|
|
|
|
[NonAction]
|
|
public virtual ServerInfo GetServerInfo()
|
|
{
|
|
return ServerInfoHelper.GetServerInfo(base.Context);
|
|
}
|
|
}
|
|
} |