mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Fixed logger not sending emails correctly.
This commit is contained in:
parent
fc08678d7d
commit
e4ffc56020
@ -9,6 +9,7 @@ using Teknik.Areas.Error.ViewModels;
|
||||
using Teknik.Controllers;
|
||||
using Teknik.Filters;
|
||||
using Teknik.Utilities;
|
||||
using Teknik.Logging;
|
||||
|
||||
namespace Teknik.Areas.Error.Controllers
|
||||
{
|
||||
@ -27,10 +28,18 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
string errorMessage = "General Exception";
|
||||
if (Request != null && Request.Url != null)
|
||||
{
|
||||
errorMessage += " on page: " + Request.Url.AbsoluteUri;
|
||||
}
|
||||
|
||||
Logger.WriteEntry(LogLevel.Error, errorMessage, exception);
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Exception = exception;
|
||||
|
||||
return View("/Areas/Error/Views/Error/Exception.cshtml", model);
|
||||
return View("~/Areas/Error/Views/Error/Exception.cshtml", model);
|
||||
}
|
||||
|
||||
[TrackPageView]
|
||||
@ -46,11 +55,19 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
string errorMessage = "General HTTP Exception";
|
||||
if (Request != null && Request.Url != null)
|
||||
{
|
||||
errorMessage += " on page: " + Request.Url.AbsoluteUri;
|
||||
}
|
||||
|
||||
Logger.WriteEntry(LogLevel.Error, errorMessage, exception);
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Description = exception.Message;
|
||||
model.Exception = exception;
|
||||
|
||||
return View("/Areas/Error/Views/Error/General.cshtml", model);
|
||||
return View("~/Areas/Error/Views/Error/General.cshtml", model);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
@ -65,10 +82,18 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
string errorMessage = "Access Denied";
|
||||
if (Request != null && Request.Url != null)
|
||||
{
|
||||
errorMessage += " on page: " + Request.Url.AbsoluteUri;
|
||||
}
|
||||
|
||||
Logger.WriteEntry(LogLevel.Error, errorMessage, exception);
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Exception = exception;
|
||||
|
||||
return View("/Areas/Error/Views/Error/Http403.cshtml", model);
|
||||
return View("~/Areas/Error/Views/Error/Http403.cshtml", model);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
@ -83,10 +108,18 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
string errorMessage = "Page Not Found";
|
||||
if (Request != null && Request.Url != null)
|
||||
{
|
||||
errorMessage += " for page: " + Request.Url.AbsoluteUri;
|
||||
}
|
||||
|
||||
Logger.WriteEntry(LogLevel.Error, errorMessage, exception);
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Exception = exception;
|
||||
|
||||
return View("/Areas/Error/Views/Error/Http404.cshtml", model);
|
||||
return View("~/Areas/Error/Views/Error/Http404.cshtml", model);
|
||||
}
|
||||
|
||||
[TrackPageView]
|
||||
@ -102,10 +135,18 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
string errorMessage = "Server Error";
|
||||
if (Request != null && Request.Url != null)
|
||||
{
|
||||
errorMessage += " on page: " + Request.Url.AbsoluteUri;
|
||||
}
|
||||
|
||||
Logger.WriteEntry(LogLevel.Error, errorMessage, exception);
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Exception = exception;
|
||||
|
||||
return View("/Areas/Error/Views/Error/Http500.cshtml", model);
|
||||
return View("~/Areas/Error/Views/Error/Http500.cshtml", model);
|
||||
}
|
||||
|
||||
private string GetIPAddress()
|
||||
|
@ -692,6 +692,10 @@
|
||||
<Project>{f0da1b67-af92-4b4a-8669-7e81645ff996}</Project>
|
||||
<Name>Configuration</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Utilities\Logging\Logging.csproj">
|
||||
<Project>{77e865fd-f08b-4f07-9676-bc2fdcc7244c}</Project>
|
||||
<Name>Logging</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Utilities\Piwik\Piwik.csproj">
|
||||
<Project>{c492c2c6-d45a-498b-84a2-6d4c8bf9de77}</Project>
|
||||
<Name>Piwik</Name>
|
||||
|
@ -10,8 +10,10 @@ using Teknik.Utilities;
|
||||
|
||||
namespace Teknik.Logging
|
||||
{
|
||||
public static class Logging
|
||||
public static class Logger
|
||||
{
|
||||
private static object Locker = new object();
|
||||
|
||||
private static Config m_Config
|
||||
{
|
||||
get
|
||||
@ -60,6 +62,9 @@ namespace Teknik.Logging
|
||||
Enum.TryParse(m_Config.LoggingConfig.EmailLevel, out minLogLevel);
|
||||
|
||||
if (log.Level >= minLogLevel)
|
||||
{
|
||||
// Lock the file processing so only 1 thread is working on the log file at a time
|
||||
lock (Locker)
|
||||
{
|
||||
if (!Directory.Exists(m_Config.LoggingConfig.OutputDirectory))
|
||||
{
|
||||
@ -99,7 +104,8 @@ namespace Teknik.Logging
|
||||
}
|
||||
|
||||
// We have rotated if needed, so let's write the entry
|
||||
File.AppendAllText(logFile, log.ToString());
|
||||
File.AppendAllText(logFile, log.ToString() + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
// Send Email Message if enabled
|
||||
@ -110,7 +116,7 @@ namespace Teknik.Logging
|
||||
Enum.TryParse(m_Config.LoggingConfig.EmailLevel, out minEmailLevel);
|
||||
if (log.Level >= minEmailLevel)
|
||||
{
|
||||
string subject = string.Format("{0} Log Message");
|
||||
string subject = string.Format("{0} Log Message", log.Level);
|
||||
string message = "Message: " + log.Message;
|
||||
if (log.Exception != null)
|
||||
{
|
||||
@ -144,7 +150,8 @@ namespace Teknik.Logging
|
||||
|
||||
client.Send(mail);
|
||||
}
|
||||
catch (Exception) { /* don't handle something in the handler */ }
|
||||
catch (Exception ex) { /* don't handle something in the handler */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Logging.cs" />
|
||||
<Compile Include="Logger.cs" />
|
||||
<Compile Include="LogLevel.cs" />
|
||||
<Compile Include="LogMessage.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user