Skip to content

Commit

Permalink
Fixes Event Log from Failing Silently during Application Startup (#4178)
Browse files Browse the repository at this point in the history
* Added try-catch block to prevent event logs from silently failing

* Updated exception handling to catch specific exception
  • Loading branch information
SkyeHoefling authored Oct 12, 2020
1 parent 83af9dd commit 30cd13a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions DNN Platform/Library/Services/Log/EventLog/LogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace DotNetNuke.Services.Log.EventLog
using System.Threading;
using System.Web;
using System.Xml;

using DotNetNuke.Abstractions.Logging;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
Expand Down Expand Up @@ -45,14 +46,21 @@ public void AddLog(LogInfo logInfo)
}

if (string.IsNullOrEmpty(logInfo.LogUserName))
{
if (HttpContext.Current != null)
{
if (HttpContext.Current.Request.IsAuthenticated)
{
logInfo.LogUserName = UserController.Instance.GetCurrentUserInfo().Username;
}
}
{
if (HttpContext.Current != null)
{
try
{
if (HttpContext.Current.Request.IsAuthenticated)
{
logInfo.LogUserName = UserController.Instance.GetCurrentUserInfo().Username;
}
}
catch (HttpException exception)
{
Logger.Error("Unable to retrieve HttpContext.Request, ignoring LogUserName", exception);
}
}
}

// Get portal name if name isn't set
Expand Down

0 comments on commit 30cd13a

Please sign in to comment.