Remove Log4Net
Add NLog
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
namespace MileageTraker.Web.Attributes
|
namespace MileageTraker.Web.Attributes
|
||||||
{
|
{
|
||||||
@@ -17,8 +18,8 @@ namespace MileageTraker.Web.Attributes
|
|||||||
|
|
||||||
var hostAddress = filterContext.HttpContext.Request.UserHostAddress;
|
var hostAddress = filterContext.HttpContext.Request.UserHostAddress;
|
||||||
|
|
||||||
log4net.LogManager.GetLogger(loggerName)
|
LogManager.GetLogger(loggerName)
|
||||||
.InfoFormat("UserHostAddress: {0}, username: {1}, params: {{{2}}}", hostAddress, username, @params);
|
.Info("UserHostAddress: {0}, username: {1}, params: {{{2}}}", hostAddress, username, @params);
|
||||||
}
|
}
|
||||||
base.OnActionExecuting(filterContext);
|
base.OnActionExecuting(filterContext);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using MileageTraker.Web.Attributes;
|
|||||||
using MileageTraker.Web.DAL;
|
using MileageTraker.Web.DAL;
|
||||||
using MileageTraker.Web.Email;
|
using MileageTraker.Web.Email;
|
||||||
using MileageTraker.Web.ViewModels.Account;
|
using MileageTraker.Web.ViewModels.Account;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
namespace MileageTraker.Web.Controllers
|
namespace MileageTraker.Web.Controllers
|
||||||
{
|
{
|
||||||
@@ -45,19 +46,19 @@ namespace MileageTraker.Web.Controllers
|
|||||||
catch (UserAccountDisabledException)
|
catch (UserAccountDisabledException)
|
||||||
{
|
{
|
||||||
var errorMessage = "Account is disabled for " + model.Username + ".";
|
var errorMessage = "Account is disabled for " + model.Username + ".";
|
||||||
log4net.LogManager.GetLogger("AccountController.Login").InfoFormat(errorMessage);
|
LogManager.GetLogger("AccountController.Login").Info(errorMessage);
|
||||||
ModelState.AddModelError("", errorMessage);
|
ModelState.AddModelError("", errorMessage);
|
||||||
}
|
}
|
||||||
catch (UserLockedOutException)
|
catch (UserLockedOutException)
|
||||||
{
|
{
|
||||||
var errorMessage = "Too many failed password attempts for " + model.Username + ". Account is locked. " + @"Use 'Forgot Password' or contact " + "administrator to unlock.";
|
var errorMessage = "Too many failed password attempts for " + model.Username + ". Account is locked. " + @"Use 'Forgot Password' or contact " + "administrator to unlock.";
|
||||||
log4net.LogManager.GetLogger("AccountController.Login").InfoFormat(errorMessage);
|
LogManager.GetLogger("AccountController.Login").Info(errorMessage);
|
||||||
ModelState.AddModelError("", errorMessage);
|
ModelState.AddModelError("", errorMessage);
|
||||||
}
|
}
|
||||||
catch (UninitializedAccountException)
|
catch (UninitializedAccountException)
|
||||||
{
|
{
|
||||||
var errorMessage = "Account for " + model.Username + " has not been initialized. " + @"Please check your email for initialization instructions.";
|
var errorMessage = "Account for " + model.Username + " has not been initialized. " + @"Please check your email for initialization instructions.";
|
||||||
log4net.LogManager.GetLogger("AccountController.Login").InfoFormat(errorMessage);
|
LogManager.GetLogger("AccountController.Login").Info(errorMessage);
|
||||||
ModelState.AddModelError("", errorMessage);
|
ModelState.AddModelError("", errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using MileageTraker.Web.DAL;
|
|||||||
using MileageTraker.Web.Models;
|
using MileageTraker.Web.Models;
|
||||||
using MileageTraker.Web.Utility;
|
using MileageTraker.Web.Utility;
|
||||||
using MileageTraker.Web.ViewModels.Account;
|
using MileageTraker.Web.ViewModels.Account;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
namespace MileageTraker.Web.Controllers
|
namespace MileageTraker.Web.Controllers
|
||||||
{
|
{
|
||||||
@@ -30,7 +31,7 @@ namespace MileageTraker.Web.Controllers
|
|||||||
var action = filterContext.RouteData.Values["action"].ToString();
|
var action = filterContext.RouteData.Values["action"].ToString();
|
||||||
var loggerName = string.Format("{0}Controller.{1}", controller, action);
|
var loggerName = string.Format("{0}Controller.{1}", controller, action);
|
||||||
|
|
||||||
log4net.LogManager.GetLogger(loggerName).Error(string.Empty, filterContext.Exception);
|
LogManager.GetLogger(loggerName).Error(filterContext.Exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnException(filterContext);
|
base.OnException(filterContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Net.Mail;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Web.Security;
|
using System.Web.Security;
|
||||||
using MileageTraker.Web.Models;
|
using MileageTraker.Web.Models;
|
||||||
using log4net;
|
using NLog;
|
||||||
|
|
||||||
namespace MileageTraker.Web.Email
|
namespace MileageTraker.Web.Email
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,7 @@ namespace MileageTraker.Web.Email
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class EmailNotificationService
|
public class EmailNotificationService
|
||||||
{
|
{
|
||||||
private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
private readonly string _emaialFromAddress;
|
private readonly string _emaialFromAddress;
|
||||||
private readonly string _resetPasswordSubject;
|
private readonly string _resetPasswordSubject;
|
||||||
@@ -71,7 +71,7 @@ namespace MileageTraker.Web.Email
|
|||||||
}
|
}
|
||||||
catch (SmtpException ex)
|
catch (SmtpException ex)
|
||||||
{
|
{
|
||||||
Logger.Error("Failed to send mail", ex);
|
Logger.Error(ex, "Failed to send mail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using MileageTraker.Web.DAL;
|
using MileageTraker.Web.DAL;
|
||||||
using MileageTraker.Web.Models;
|
using MileageTraker.Web.Models;
|
||||||
using log4net;
|
using NLog;
|
||||||
|
|
||||||
namespace MileageTraker.Web.Email
|
namespace MileageTraker.Web.Email
|
||||||
{
|
{
|
||||||
public class ServiceReminderEmailService : IDisposable
|
public class ServiceReminderEmailService : IDisposable
|
||||||
{
|
{
|
||||||
private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
protected readonly DataService DataService = new DataService();
|
protected readonly DataService DataService = new DataService();
|
||||||
protected readonly EmailNotificationService EmailService = new EmailNotificationService();
|
protected readonly EmailNotificationService EmailService = new EmailNotificationService();
|
||||||
@@ -20,7 +20,7 @@ namespace MileageTraker.Web.Email
|
|||||||
Logger.Info("Starting vehicle service notifications");
|
Logger.Info("Starting vehicle service notifications");
|
||||||
var serviceReminders = DataService.GetUpcomingServiceReminders().ToList();
|
var serviceReminders = DataService.GetUpcomingServiceReminders().ToList();
|
||||||
|
|
||||||
Logger.Debug("Got " + serviceReminders.Count + " service reminders.");
|
Logger.Info("Got " + serviceReminders.Count + " service reminders.");
|
||||||
|
|
||||||
SendAdminEmails(serviceReminders);
|
SendAdminEmails(serviceReminders);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
|
||||||
|
autoReload="true"
|
||||||
|
throwExceptions="false"
|
||||||
|
internalLogLevel="Info" internalLogFile="c:\temp\nlog-internal.log" >
|
||||||
|
|
||||||
|
|
||||||
|
<!-- optional, add some variabeles
|
||||||
|
https://github.com/nlog/NLog/wiki/Configuration-file#variables
|
||||||
|
-->
|
||||||
|
<variable name="myvar" value="myvalue"/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
See https://github.com/nlog/nlog/wiki/Configuration-file
|
||||||
|
for information on customizing logging rules and outputs.
|
||||||
|
-->
|
||||||
|
<targets>
|
||||||
|
<target name="logfile" xsi:type="File" fileName="c:\temp\MileageTraker.Log" />
|
||||||
|
<!--
|
||||||
|
add your targets here
|
||||||
|
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
|
||||||
|
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Writing events to the a file with the date in the filename.
|
||||||
|
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
|
||||||
|
layout="${longdate} ${uppercase:${level}} ${message}" />
|
||||||
|
-->
|
||||||
|
</targets>
|
||||||
|
|
||||||
|
<rules>
|
||||||
|
<!-- add your logging rules here -->
|
||||||
|
<logger name="*" minlevel="Debug" writeTo="logfile" />
|
||||||
|
<!--
|
||||||
|
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
|
||||||
|
<logger name="*" minlevel="Debug" writeTo="f" />
|
||||||
|
-->
|
||||||
|
</rules>
|
||||||
|
</nlog>
|
||||||
+2479
File diff suppressed because it is too large
Load Diff
@@ -33,4 +33,3 @@ using System.Runtime.InteropServices;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configSections>
|
<configSections>
|
||||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
|
||||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||||
</configSections>
|
</configSections>
|
||||||
@@ -101,46 +100,6 @@
|
|||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
<log4net>
|
|
||||||
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
|
|
||||||
<file value="Logs\MileageTraker.log" />
|
|
||||||
<appendToFile value="true" />
|
|
||||||
<datePattern value="yyyyMMdd" />
|
|
||||||
<rollingStyle value="Date" />
|
|
||||||
|
|
||||||
<maxSizeRollBackups value="250" />
|
|
||||||
|
|
||||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
|
||||||
<layout type="log4net.Layout.PatternLayout">
|
|
||||||
<conversionPattern value="%date [%thread] %level %logger - %message%newline%exception" />
|
|
||||||
</layout>
|
|
||||||
</appender>
|
|
||||||
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
|
|
||||||
<file value="Logs\MileageTraker.error.log" />
|
|
||||||
<appendToFile value="true" />
|
|
||||||
<datePattern value="yyyyMMdd" />
|
|
||||||
<rollingStyle value="Date" />
|
|
||||||
|
|
||||||
<maxSizeRollBackups value="250" />
|
|
||||||
|
|
||||||
<filter type="log4net.Filter.LevelRangeFilter">
|
|
||||||
<acceptOnMatch value="true" />
|
|
||||||
|
|
||||||
<levelMin value="ERROR" />
|
|
||||||
<levelMax value="FATAL" />
|
|
||||||
</filter>
|
|
||||||
|
|
||||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
|
||||||
<layout type="log4net.Layout.PatternLayout">
|
|
||||||
<conversionPattern value="%date [%thread] %level %logger - %message%newline%exception" />
|
|
||||||
</layout>
|
|
||||||
</appender>
|
|
||||||
<root>
|
|
||||||
<level value="DEBUG" />
|
|
||||||
<appender-ref ref="FileAppender" />
|
|
||||||
<appender-ref ref="ErrorAppender" />
|
|
||||||
</root>
|
|
||||||
</log4net>
|
|
||||||
<entityFramework>
|
<entityFramework>
|
||||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
|
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
|
||||||
<parameters>
|
<parameters>
|
||||||
|
|||||||
+10
-4
@@ -79,10 +79,6 @@
|
|||||||
<HintPath>..\packages\Hangfire.SqlServer.1.5.2\lib\net45\Hangfire.SqlServer.dll</HintPath>
|
<HintPath>..\packages\Hangfire.SqlServer.1.5.2\lib\net45\Hangfire.SqlServer.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Microsoft.Owin.3.0.0\lib\net45\Microsoft.Owin.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Owin.3.0.0\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||||
@@ -107,6 +103,10 @@
|
|||||||
<HintPath>..\packages\Newtonsoft.Json.5.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.5.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\NLog.4.2.0\lib\net45\NLog.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
@@ -343,6 +343,12 @@
|
|||||||
<Content Include="fonts\fontawesome-webfont.ttf" />
|
<Content Include="fonts\fontawesome-webfont.ttf" />
|
||||||
<Content Include="fonts\fontawesome-webfont.eot" />
|
<Content Include="fonts\fontawesome-webfont.eot" />
|
||||||
<Content Include="fonts\FontAwesome.otf" />
|
<Content Include="fonts\FontAwesome.otf" />
|
||||||
|
<Content Include="NLog.config">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<None Include="NLog.xsd">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</None>
|
||||||
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
|
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
|
||||||
<Content Include="Scripts\jquery-2.1.4.js" />
|
<Content Include="Scripts\jquery-2.1.4.js" />
|
||||||
<Content Include="Scripts\jquery-2.1.4.min.js" />
|
<Content Include="Scripts\jquery-2.1.4.min.js" />
|
||||||
|
|||||||
+3
-1
@@ -14,7 +14,6 @@
|
|||||||
<package id="jQuery.Numeric" version="1.4.1" targetFramework="net45" />
|
<package id="jQuery.Numeric" version="1.4.1" targetFramework="net45" />
|
||||||
<package id="jQuery.Validation" version="1.13.1" targetFramework="net45" />
|
<package id="jQuery.Validation" version="1.13.1" targetFramework="net45" />
|
||||||
<package id="jQuery.vsdoc" version="1.6" />
|
<package id="jQuery.vsdoc" version="1.6" />
|
||||||
<package id="log4net" version="2.0.3" targetFramework="net40" />
|
|
||||||
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
|
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
|
||||||
@@ -24,6 +23,9 @@
|
|||||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
|
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
|
||||||
<package id="MvcCheckBoxList" version="1.4.4.5" targetFramework="net40" requireReinstallation="True" />
|
<package id="MvcCheckBoxList" version="1.4.4.5" targetFramework="net40" requireReinstallation="True" />
|
||||||
<package id="Newtonsoft.Json" version="5.0.1" targetFramework="net45" />
|
<package id="Newtonsoft.Json" version="5.0.1" targetFramework="net45" />
|
||||||
|
<package id="NLog" version="4.2.0" targetFramework="net45" />
|
||||||
|
<package id="NLog.Config" version="4.2.0" targetFramework="net45" />
|
||||||
|
<package id="NLog.Schema" version="4.0.0" targetFramework="net45" />
|
||||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||||
<package id="Twitter.Bootstrap" version="2.2.2" targetFramework="net40" />
|
<package id="Twitter.Bootstrap" version="2.2.2" targetFramework="net40" />
|
||||||
</packages>
|
</packages>
|
||||||
Reference in New Issue
Block a user