mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.1 KiB
62 lines
2.1 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using Google.Cloud.Diagnostics.Common;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Log;
|
|
|
|
namespace Squidex.Extensions.APM.Stackdriver
|
|
{
|
|
internal sealed class StackdriverExceptionHandler : ILogAppender
|
|
{
|
|
private readonly IContextExceptionLogger logger;
|
|
private readonly HttpContextWrapper httpContextWrapper;
|
|
|
|
public sealed class HttpContextWrapper : IContextWrapper
|
|
{
|
|
private readonly IHttpContextAccessor httpContextAccessor;
|
|
|
|
internal HttpContextWrapper(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
this.httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
public string GetHttpMethod()
|
|
{
|
|
return httpContextAccessor.HttpContext?.Request?.Method?.ToString();
|
|
}
|
|
|
|
public string GetUri()
|
|
{
|
|
return httpContextAccessor.HttpContext?.Request?.GetDisplayUrl();
|
|
}
|
|
|
|
public string GetUserAgent()
|
|
{
|
|
return httpContextAccessor.HttpContext?.Request?.Headers["User-Agent"].ToString();
|
|
}
|
|
}
|
|
|
|
public StackdriverExceptionHandler(IContextExceptionLogger logger, IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
this.logger = logger;
|
|
|
|
httpContextWrapper = new HttpContextWrapper(httpContextAccessor);
|
|
}
|
|
|
|
public void Append(IObjectWriter writer, SemanticLogLevel logLevel, Exception exception)
|
|
{
|
|
if (exception != null && exception is not DomainException)
|
|
{
|
|
logger.Log(exception, httpContextWrapper);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|