1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 23:31:13 -05:00

refactor logging in pretty big overhaul

This commit is contained in:
RaidMax
2020-11-11 17:31:26 -06:00
parent f8c886d9db
commit 04fe6836c6
86 changed files with 1603 additions and 1534 deletions

View File

@ -1,12 +1,13 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using WebfrontCore.Controllers.API.Dtos;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace WebfrontCore.Controllers.API
{
@ -20,7 +21,7 @@ namespace WebfrontCore.Controllers.API
private readonly IResourceQueryHelper<FindClientRequest, FindClientResult> _clientQueryHelper;
private readonly ILogger _logger;
public ClientController(ILogger logger, IResourceQueryHelper<FindClientRequest, FindClientResult> clientQueryHelper)
public ClientController(ILogger<ClientController> logger, IResourceQueryHelper<FindClientRequest, FindClientResult> clientQueryHelper)
{
_logger = logger;
_clientQueryHelper = clientQueryHelper;
@ -53,8 +54,7 @@ namespace WebfrontCore.Controllers.API
catch (Exception e)
{
_logger.WriteWarning($"Failed to retrieve clients with query - {request.ToDebugString()}");
_logger.WriteDebug(e.GetExceptionInfo());
_logger.LogWarning(e, "Failed to retrieve clients with query - {@request}", request);
return StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse()
{

View File

@ -171,7 +171,7 @@ namespace WebfrontCore.Controllers
var meta = await ProfileMetaListViewComponent.GetClientMeta(_metaService, metaFilterType, Client.Level, request);
if (meta.Count() == 0)
if (!meta.Any())
{
return Ok();
}

View File

@ -3,19 +3,22 @@ using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace WebfrontCore.Controllers
{
public class HomeController : BaseController
{
private readonly ITranslationLookup _translationLookup;
private readonly ILogger _logger;
public HomeController(IManager manager, ITranslationLookup translationLookup) : base(manager)
public HomeController(ILogger<HomeController> logger, IManager manager, ITranslationLookup translationLookup) : base(manager)
{
_logger = logger;
_translationLookup = translationLookup;
}
@ -43,10 +46,7 @@ namespace WebfrontCore.Controllers
public IActionResult Error()
{
var exceptionFeature = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
Manager.GetLogger(0).WriteError($"[Webfront] {exceptionFeature.Error.Message}");
Manager.GetLogger(0).WriteDebug(exceptionFeature.Path);
Manager.GetLogger(0).WriteDebug(exceptionFeature.Error.StackTrace);
_logger.LogError("[Webfront] {path} {message} {@exception}", exceptionFeature.Path, exceptionFeature.Error.Message, exceptionFeature.Error);
ViewBag.Description = Localization["WEBFRONT_ERROR_DESC"];
ViewBag.Title = Localization["WEBFRONT_ERROR_TITLE"];
return View(exceptionFeature.Error);

View File

@ -1,9 +1,8 @@
using Microsoft.AspNetCore.Http;
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace WebfrontCore.Middleware
{
@ -22,7 +21,7 @@ namespace WebfrontCore.Middleware
/// </summary>
/// <param name="nextRequest"></param>
/// <param name="whitelistedIps">list of textual ip addresses</param>
public IPWhitelist(RequestDelegate nextRequest, ILogger logger, string[] whitelistedIps)
public IPWhitelist(RequestDelegate nextRequest, ILogger<IPWhitelist> logger, string[] whitelistedIps)
{
_whitelistedIps = whitelistedIps.Select(_ip => System.Net.IPAddress.Parse(_ip).GetAddressBytes()).ToArray();
_nextRequest = nextRequest;
@ -31,21 +30,21 @@ namespace WebfrontCore.Middleware
public async Task Invoke(HttpContext context)
{
bool isAlllowed = true;
var isAllowed = true;
if (_whitelistedIps.Length > 0)
{
isAlllowed = _whitelistedIps.Any(_ip => _ip.SequenceEqual(context.Connection.RemoteIpAddress.GetAddressBytes()));
isAllowed = _whitelistedIps.Any(_ip => _ip.SequenceEqual(context.Connection.RemoteIpAddress.GetAddressBytes()));
}
if (isAlllowed)
if (isAllowed)
{
await _nextRequest.Invoke(context);
}
else
{
_logger.WriteInfo($"Blocking HTTP request from {context.Connection.RemoteIpAddress.ToString()}");
_logger.LogDebug("Blocking HTTP request from {ipAddress}", context.Connection.RemoteIpAddress);
context.Abort();
}
}

View File

@ -79,11 +79,11 @@ namespace WebfrontCore
});
#if DEBUG
mvcBuilder = mvcBuilder.AddRazorRuntimeCompilation();
/*mvcBuilder = mvcBuilder.AddRazorRuntimeCompilation();
services.Configure<RazorViewEngineOptions>(_options =>
{
_options.ViewLocationFormats.Add(@"/Views/Plugins/{1}/{0}" + RazorViewEngine.ViewExtension);
});
});*/
#endif
foreach (var asm in pluginAssemblies())
@ -103,13 +103,6 @@ namespace WebfrontCore
options.LoginPath = "/";
});
#if DEBUG
services.AddLogging(_builder =>
{
_builder.AddDebug();
});
#endif
services.AddSingleton(Program.Manager);
services.AddSingleton<IResourceQueryHelper<ChatSearchQuery, MessageResponse>, ChatResourceQueryHelper>();
services.AddTransient<IValidator<FindClientRequest>, FindClientRequestValidator>();
@ -121,7 +114,6 @@ namespace WebfrontCore
services.AddSingleton(Program.ApplicationServiceProvider.GetService<IDatabaseContextFactory>());
services.AddSingleton(Program.ApplicationServiceProvider.GetService<IAuditInformationRepository>());
services.AddSingleton(Program.ApplicationServiceProvider.GetService<ITranslationLookup>());
services.AddSingleton(Program.ApplicationServiceProvider.GetService<SharedLibraryCore.Interfaces.ILogger>());
services.AddSingleton(Program.ApplicationServiceProvider.GetService<IEnumerable<IManagerCommand>>());
services.AddSingleton(Program.ApplicationServiceProvider.GetService<IMetaService>());
services.AddSingleton(Program.ApplicationServiceProvider.GetService<ApplicationConfiguration>());
@ -152,7 +144,7 @@ namespace WebfrontCore
if (Program.Manager.GetApplicationSettings().Configuration().EnableWebfrontConnectionWhitelist)
{
app.UseMiddleware<IPWhitelist>(manager.GetLogger(0), manager.GetApplicationSettings().Configuration().WebfrontConnectionWhitelist);
app.UseMiddleware<IPWhitelist>(Program.ApplicationServiceProvider.GetService<ILogger<IPWhitelist>>(), manager.GetApplicationSettings().Configuration().WebfrontConnectionWhitelist);
}
app.UseStaticFiles();

View File

@ -1,4 +1,4 @@
@model List<SharedLibraryCore.Dtos.PlayerInfo>
@model IList<SharedLibraryCore.Dtos.PlayerInfo>
@{
var loc = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex;
}

View File

@ -1,7 +1,7 @@
@{
Layout = null;
}
@model List<SharedLibraryCore.Dtos.PenaltyInfo>
@model IList<SharedLibraryCore.Dtos.PenaltyInfo>
@{
foreach (var penalty in Model)

View File

@ -1,4 +1,4 @@
@model int
@model int?
@{
ViewData["Title"] = "Error";
}
@ -6,7 +6,7 @@
<h4 class="text-danger">@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_GENERIC_TITLE"]</h4>
<h4 class="text-danger">@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_GENERIC_DESC"]</h4>
<strong class="text-warning">
@if (Model == 404)
@if (Model.HasValue && Model.Value == 404)
{
@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_NOTFOUND"]
}

View File

@ -81,7 +81,13 @@
<ItemGroup>
<Folder Include="wwwroot\lib\canvas.js\" />
</ItemGroup>
<Target Name="RemoveSatellitesFromPublish" AfterTargets="ComputeFilesToPublish">
<ItemGroup>
<ResolvedFileToPublish Remove="@(ReferenceSatellitePaths)" />
</ItemGroup>
</Target>
<ItemGroup>
<ProjectReference Include="..\Plugins\Web\StatsWeb\StatsWeb.csproj" />
<ProjectReference Include="..\SharedLibraryCore\SharedLibraryCore.csproj" />