Remotely/Server/Pages/Error.cshtml.cs
Jared Goodwin 3bcb4d2ede Logging updates.
Fix log entry.

Additional logging.  Add environment badge.

Add logging.

Updater tweaks.

Add logging.

Updater changes.
2021-07-29 07:56:33 -07:00

52 lines
1.7 KiB
C#

using System.Diagnostics;
using Remotely.Server.Services;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Remotely.Shared.Enums;
namespace Remotely.Server.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel
{
public ErrorModel(DataService dataService)
{
this.DataService = dataService;
}
public string RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private DataService DataService { get; }
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
try
{
var user = DataService.GetUserByName(User.Identity.Name);
var feature = this.HttpContext.Features.Get<IExceptionHandlerFeature>();
if (feature?.Error != null)
{
var error = feature.Error;
while (error != null)
{
var logEntry = new Remotely.Shared.Models.EventLog()
{
EventType = EventType.Error,
Message = error.Message,
Source = error.Source,
StackTrace = error.StackTrace,
OrganizationID = user?.OrganizationID
};
DataService.WriteEvent(logEntry);
error = error.InnerException;
}
}
}
catch { }
}
}
}