Better logs for common ActionLog attribute paramters

This commit is contained in:
2014-01-23 13:59:15 -05:00
parent 30beccfc83
commit bb5dab48a0
6 changed files with 29 additions and 9 deletions
+3 -3
View File
@@ -13,12 +13,12 @@ namespace MileageTraker.Web.Attributes
var action = filterContext.RouteData.Values["action"].ToString(); var action = filterContext.RouteData.Values["action"].ToString();
var username = filterContext.HttpContext.User.Identity.Name; var username = filterContext.HttpContext.User.Identity.Name;
var loggerName = string.Format("{0}Controller.{1}", controller, action); var loggerName = string.Format("{0}Controller.{1}", controller, action);
var @params = string.Join(", ", filterContext.ActionParameters.Select(i => i.Key + ": " + i.Value)); var @params = string.Join(", ", filterContext.ActionParameters.Select(i => i.Key + ": {" + i.Value +"}"));
var hostAddress = "UserHostAddress: " + filterContext.HttpContext.Request.UserHostAddress; var hostAddress = filterContext.HttpContext.Request.UserHostAddress;
log4net.LogManager.GetLogger(loggerName) log4net.LogManager.GetLogger(loggerName)
.InfoFormat("{0}, username: {1}, {2}", hostAddress, username, @params); .InfoFormat("UserHostAddress: {0}, username: {1}, params: {{{2}}}", hostAddress, username, @params);
} }
base.OnActionExecuting(filterContext); base.OnActionExecuting(filterContext);
} }
+1 -6
View File
@@ -1,11 +1,6 @@
using System; using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using MileageTraker.Web.DAL; using MileageTraker.Web.DAL;
using MileageTraker.Web.Models;
namespace MileageTraker.Web.Attributes namespace MileageTraker.Web.Attributes
{ {
+6
View File
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using MileageTraker.Web.Utility;
namespace MileageTraker.Web.Models namespace MileageTraker.Web.Models
{ {
@@ -33,5 +34,10 @@ namespace MileageTraker.Web.Models
{ {
return new MileageLogTypeWrapper { Enum = c }; return new MileageLogTypeWrapper { Enum = c };
} }
public override string ToString()
{
return Enum.GetDisplayName();
}
} }
} }
@@ -110,5 +110,12 @@ namespace MileageTraker.Web.ViewModels.CreateLog
if (result != null) if (result != null)
yield return result; yield return result;
} }
public override string ToString()
{
return string.Format(
"vehicle: {0}, odo: {1}, type: {2}, city: {3}, gas: {4}, purpose: {5}, date: {6}",
VehicleId, EndOdometer, LogType, CityName, GasPurchased, Purpose, Date.ToShortDateString());
}
} }
} }
+7
View File
@@ -147,5 +147,12 @@ namespace MileageTraker.Web.ViewModels.Log
} }
} }
} }
public override string ToString()
{
return string.Format(
"vehicle: {0}, odo: {1}, type: {2}, city: {3}, gas: {4}, purpose: {5}, date: {6}",
VehicleId, EndOdometer, LogType, CityName, GasPurchased, Purpose, Date.ToShortDateString());
}
} }
} }
+5
View File
@@ -6,5 +6,10 @@ namespace MileageTraker.Web.ViewModels
{ {
public SelectList Available { get; set; } public SelectList Available { get; set; }
public int Selected { get; set; } public int Selected { get; set; }
public override string ToString()
{
return Selected.ToString();
}
} }
} }