public EncoreClient() { encoreClient = new Utilities(); encoreInstance = new Instance(); encoreLogDetail = new LogDetail(); encoreLang = new Language(); }
/// <summary> /// Insert Log Detail /// </summary> /// <param name="logId"></param> /// <param name="colName"></param> /// <param name="disColName"></param> /// <param name="oldValue"></param> /// <param name="newValue"></param> public void InsertLogDetail(string logId, string colName, string disColName, string oldValue, string newValue) { try { if ((logId != null) && (!string.Empty.Equals(colName))) { // Set info LogDetail objInfo = new LogDetail(); objInfo.DetailId = UniqueId; objInfo.LogId = logId; objInfo.ColumnName = colName; objInfo.DisplayColumnName = disColName; objInfo.OldValue = oldValue; objInfo.NewValue = newValue; // Insert to DB dbContext.LogDetails.InsertOnSubmit(objInfo); dbContext.SubmitChanges(); } } catch (Exception ex) { throw ex; } }
private LogDetail GetLogDetail(IInvocation invocation) { var logParameters = new List <LogParameter>(); for (int i = 0; i < invocation.Arguments.Length; i++) { logParameters.Add(new LogParameter { Name = invocation.GetConcreteMethod().GetParameters()[i].Name, Value = invocation.Arguments[i], Type = invocation.Arguments[i].GetType().Name }); } var logDetail = new LogDetail { MethodName = invocation.Method.Name, LogParameters = logParameters }; return(logDetail); }
public override void OnEntry(MethodExecutionArgs args) { if (!_loggerService.IsInfoEnabled) { return; } var logParameters = args.Method.GetParameters().Select((t, i) => new LogParameter() { Name = t.Name, Type = t.ParameterType.Name, Value = args.Arguments.GetArgument(i) }).ToList(); var logDetail = new LogDetail { FullName = args.Method.DeclaringType == null ? null : args.Method.DeclaringType.Name, MethodName = args.Method.Name, Parameters = logParameters }; _loggerService.Info(logDetail); }
private string GetLogDetail(IInvocation invocation) { var logParameters = new List <LogParameter>(); for (var i = 0; i < invocation.Arguments.Length; i++) { logParameters.Add(new LogParameter { Name = invocation.GetConcreteMethod().GetParameters()[i].Name, Value = invocation.Arguments[i], Type = invocation.Arguments[i].GetType().Name, }); } var logDetail = new LogDetail { MethodName = invocation.Method.Name, Parameters = logParameters, User = (_httpContextAccessor.HttpContext == null || _httpContextAccessor.HttpContext.User.Identity.Name == null) ? "?" : _httpContextAccessor.HttpContext.User.Identity.Name }; return(JsonConvert.SerializeObject(logDetail)); }
public PerfTracker(string name, string userId, string userName, string location, string product, string layer) { _sw = Stopwatch.StartNew(); _infoToLog = new LogDetail() { Message = name, UserId = userId, UserName = userName, Product = product, Layer = layer, Location = location, Hostname = Environment.MachineName, CorrelationId = HttpContext.Current?.Session?.SessionID, }; var beginTime = DateTime.Now; _infoToLog.AdditionalInfo = new Dictionary <string, object>() { { "Started", beginTime.ToString(CultureInfo.InvariantCulture) } }; }
private LogDetail GetLogDetail(IInvocation invocation) { var logParameters = new List <LogParameter>(); for (int i = 0; i < invocation.Arguments.Length; i++) { logParameters.Add(new LogParameter { Name = invocation.GetConcreteMethod().GetParameters()[i].Name, Value = invocation.Arguments[i], Type = invocation.Arguments[i].GetType().Name }); } var logDetail = new LogDetail { MethodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"), LogParameters = logParameters, DateTime = DateTime.Now }; return(logDetail); }
public void Intercept(IInvocation invocation) { Console.WriteLine($"{invocation.Method.Name} method invoked"); var logParameters = invocation.Method.GetParameters().Select((t, i) => new LogParameter { Name = t.Name, Type = t.ParameterType.Name, Value = invocation.Arguments[i] }).ToList(); var logDetail = new LogDetail() { FullName = invocation.Method.DeclaringType == null ? null : invocation.Method.DeclaringType.Name, MethodName = invocation.Method.Name, Parameters = logParameters }; using (var transaction = new TransactionScope(TransactionScopeOption.Suppress)) { try { //If you want to catch the error message, remove the comment line below. //int a = Convert.ToInt32("a"); _loggerService.Info(logDetail); invocation.Proceed(); transaction.Complete(); } catch (Exception ex) { _loggerService.Error(ex); Console.WriteLine($"An error has occured: {ex.Message}"); } } Console.WriteLine($"{invocation.Method.Name} method finished"); }
private static void BroardCastLogDetail(LogLevel level, string log) { if (null != s_onLogOccur) { LogDetail logDetail = new LogDetail(); logDetail.level = level; logDetail.userLog = log; string detail = log; StackTrace stackTrace = new StackTrace(true); StackFrame[] frames = stackTrace.GetFrames(); StringBuilder builder = new StringBuilder(); for(int i=2; i<frames.Length; ++i) { StackFrame f = frames[i-2]; builder.AppendFormat("\n{0} {1}:{2} Line:{3}", i-2, System.IO.Path.GetFileName(f.GetFileName()), f.GetMethod().Name, f.GetFileLineNumber()); } detail += builder.ToString(); logDetail.detail = detail; s_onLogOccur(logDetail); } }
public override void OnActionExecuting(ActionExecutingContext context) { LogDetail log = new LogDetail { DateTime = DateTime.Now, FullName = context.RouteData.Values["Controller"].ToString(), MethodName = context.RouteData.Values["Action"].ToString(), Type = LogType.Info.ToString(), Info = context.RouteData.Values["LogInfo"] != null ? context.RouteData.Values["LogInfo"].ToString() : "", IPAddress = context.HttpContext.Connection.RemoteIpAddress.ToString(), Arguments = context.ActionDescriptor.Parameters.Select((param, i) => new LogArgument { Name = param.Name, Type = param.ParameterType.Name, Value = context.HttpContext.Request.Query[param.Name].ToString() }).ToList() }; var user = context.HttpContext.Session.GetSession <User>("User"); log.UserName = user != null ? "Username: "******" | Email: " + user.Email : "Visitor"; _loggerService.Logging(log); }
private LogDetail GetLogDetail(IInvocation invocation) { var logParameters = new List <LogParameter>(); for (int i = 0; i < invocation.Arguments.Length; i++) { var logParameter = new LogParameter { Type = invocation.Arguments[i].GetType().Name, Name = invocation.GetConcreteMethod().GetParameters()[i].Name, Value = invocation.Arguments[i] }; logParameters.Add(logParameter); } var logDetail = new LogDetail { LogParameters = logParameters, MethodName = $"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}" }; return(logDetail); }
private static void BroardCastLogDetail(LogLevel level, string log) { if (null != s_onLogOccur) { LogDetail logDetail = new LogDetail(); logDetail.level = level; logDetail.userLog = log; string detail = log; StackTrace stackTrace = new StackTrace(true); StackFrame[] frames = stackTrace.GetFrames(); StringBuilder builder = new StringBuilder(); for (int i = 2; i < frames.Length; ++i) { StackFrame f = frames[i - 2]; builder.AppendFormat("\n{0} {1}:{2} Line:{3}", i - 2, System.IO.Path.GetFileName(f.GetFileName()), f.GetMethod().Name, f.GetFileLineNumber()); } detail += builder.ToString(); logDetail.detail = detail; s_onLogOccur(logDetail); } }
public override void OnEntry(MethodExecutionArgs args) { try { var logParameters = args.Method.GetParameters().Select((t, i) => new LogParameter { Name = t.Name, Type = t.ParameterType.Name, Value = args.Arguments.GetArgument(i) }).ToList(); var logDetail = new LogDetail { FullName = args.Method.DeclaringType == null ? null : args.Method.DeclaringType.Name, MethodName = args.Method.Name, Parameters = logParameters }; _loggerService.Information(logDetail); } catch (Exception) { } }
public static LogDetail LogMethodDetail(this MethodExecutionArgs args, string customMessage = null, string aspectName = null) { var logParameters = args.Method.GetParameters().Select((t, i) => new LogParameter { Name = t.Name, Type = t.ParameterType.Name, Value = args.Arguments.GetArgument(i) }).ToList(); var logDetail = new LogDetail { NameSpace = args.Method.DeclaringType?.FullName, MethodName = args.Method.Name, CodeLine = args.Exception == null ? string.Empty : new StackTrace(args.Exception, true).GetFrame(0).GetFileLineNumber().ToString(), CustomMessage = customMessage, AspectName = aspectName, Parameters = logParameters }; return(logDetail); }
private LogDetail GetLogDetail(IInvocation invocation) { var logParameters = new List <LogParameter>(); for (int i = 0; i < invocation.Arguments.Length; i++) { logParameters.Add(new LogParameter { Name = invocation.GetConcreteMethod().GetParameters()[i].Name, Value = invocation.Arguments[i], Type = invocation.Arguments[i].GetType().Name }); } var logDetail = new LogDetail { Date = DateTime.Now, User = (_httpContextAccessor.HttpContext == null || _httpContextAccessor.HttpContext.User.Identity.Name == null) ? GetLocalIPAddress() : _httpContextAccessor.HttpContext.User.Identity.Name, MethodName = invocation.Method.Name, LogParameters = logParameters }; return(logDetail); }
public virtual void LogWebDiagnostic(string message, Dictionary <string, object> diagnosticInfo = null) { // doing this to avoid going through all the data - user, session, etc. if (_logsSettings.WriteDiagnostics) { return; } string userId, userName, location; Dictionary <string, object> webInfo = GetWebLoggingData(out userId, out userName, out location); if (diagnosticInfo != null) { foreach (var key in diagnosticInfo.Keys) { webInfo.Add(key, diagnosticInfo[key]); } } var diagInfo = new LogDetail() { Product = _logsSettings.Product, Layer = _logsSettings.Layer, Location = location, TimestampUtc = DateTime.UtcNow, UserId = userId, UserName = userName, Hostname = Environment.MachineName, CorrelationId = HttpContext.Current.Session?.SessionID, Message = message, AdditionalInfo = webInfo }; _logsWriter.WriteDiagnostic(diagInfo); }
//Burayı dahada geliştirebiliriz örneğin gelen parametre bir obje ise //içeriğini de okuyup json formatında yazabılırız //yanı adamın eskı kaydını da tutabılırız. private LogDetail GetLogDetail(IInvocation invocation) { var logParameters = new List <LogParameter>(); for (int i = 0; i < invocation.Arguments.Length; i++) { logParameters.Add(new LogParameter { //invocation.GetConcreteMethod().GetParameters()[i].Name parametreyı bu şekilde alıyoruz //Cache dekı sorunda sankı benzer bır durum var gıbı Name = invocation.GetConcreteMethod().GetParameters()[i].Name, Value = invocation.Arguments[i], Type = invocation.Arguments[i].GetType().Name }); } var logDetail = new LogDetail { MethodName = invocation.Method.Name, LogParameters = logParameters }; return(logDetail); }
protected virtual void SetPropertiesFromAdditionalInfo(LogDetail logEntry, object additionalInfo) { if (additionalInfo is Dictionary <string, object> ) { var ai = additionalInfo as Dictionary <string, object>; foreach (KeyValuePair <string, object> item in ai) { if (!logEntry.AdditionalInfo.ContainsKey(item.Key)) { logEntry.AdditionalInfo[item.Key] = item.Value; } } } else // not a dictionary { PropertyInfo[] props = additionalInfo.GetType().GetProperties(); foreach (PropertyInfo prop in props) { object propertyValue = prop.GetValue(additionalInfo); logEntry.AdditionalInfo[$"dtl-{prop.Name}"] = propertyValue.ToString(); } } }
private LogDetail GetLogDetail(IInvocation invocation) { var logParameters = new List <LogParameter>(); for (int i = 0; i < invocation.Arguments.Length; i++) { logParameters.Add(new LogParameter { Name = invocation.GetConcreteMethod().GetParameters()[i].Name, Value = invocation.Arguments[i], Type = invocation.Arguments[i].GetType().Name }); } var logDetail = new LogDetail { Email = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Email)?.Value, Target = invocation.InvocationTarget?.ToString(), MethodName = invocation.Method.Name, LogParameters = logParameters }; return(logDetail); }
LogDetail GetLogDetail(IInvocation invocation) { var logParameters = new List <LogParameter>(); for (int i = 0; i < invocation.Arguments.Length; i++) { logParameters.Add(new LogParameter { Name = invocation.GetConcreteMethod().GetParameters()[i].Name, Value = invocation.Arguments[i], Type = invocation.Arguments[i].GetType().Name }); } var logDetail = new LogDetail { MethodName = invocation.Method.Name, LogParameters = logParameters }; return(logDetail); //var logParameters = invocation.Arguments.Select(x => new LogParameter //{ // Value = x, // Type = x.GetType().Name //}).ToList(); //var logDetail = new LogDetail //{ // MethodName = invocation.Method.Name, // LogParameters = logParameters //}; //return logDetail; }
private LogDetail GetLogDetail(IInvocation invocation) // invocation equals to method { var logParameters = new List <LogParameter>(); for (int i = 0; i < invocation.Arguments.Length; i++) { logParameters.Add(new LogParameter { Name = invocation.GetConcreteMethod().GetParameters()[i].Name, // Sample : categoryId (Parameter Name) Value = invocation.Arguments[i], Type = invocation.Arguments[i].GetType().Name }); } var logDetail = new LogDetail { FullName = invocation.Method.DeclaringType == null ? null : invocation.Method.DeclaringType.Name, MethodName = invocation.Method.Name, LogParameters = logParameters, DateTime = DateTime.Now.ToString("G") }; return(logDetail); }
public static void AcceptLogRequest( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "Log")] HttpRequest req, [CosmosDB( databaseName: "azlogger", collectionName: "azlogger-logs", ConnectionStringSetting = "MyCosmosDBConnection", Id = "{sys.randguid}", PartitionKey = "/loggerName" )] out LogDetail logDetail, ILogger log) { log.LogInformation("HTTP trigger fired for log entry."); // Read from the NLOG format, like. // <parameter name='timestamp' type='System.String' layout='${longdate}'/> // <parameter name='loggerName' type='System.String' layout='${logger}'/> // <parameter name='loggerLevel' type='System.String' layout='${level}'/> // <parameter name='message' type='System.String' layout='${message}'/> string timestamp = req.Form["timestamp"]; string loggerName = req.Form["loggerName"]; string loggerLevel = req.Form["loggerLevel"]; string message = req.Form["message"]; var res = $"{timestamp} | {loggerName} | {loggerLevel.ToUpper()} | {message}"; log.LogInformation(res); // Create a new Customers object logDetail = new LogDetail(); // Create a new empty customer list on the customers object logDetail.Timestamp = timestamp; logDetail.LogLevel = loggerLevel; logDetail.LogName = loggerName; logDetail.Message = message; }
//methods public virtual void LogDiagnostic(string message, object additionalInfo = null) { LogDetail logEntry = GetWcfLogEntry(message, additionalInfo); _logsWriter.WriteUsage(logEntry); }
protected override void Append(StringBuilder builder, LogEventInfo logEvent) { LogDetail logDetail = (LogDetail)logEvent.Parameters[0]; builder.Append(logDetail.ClaimId); }
private static void AddToTable(Dictionary <logDetailName, TableBuilder> tableList, LogDetail detail) { }
//methods public virtual void Write(LogDetail infoToLog) { _logger.Write(LogEventLevel.Information, "{@LogDetail}", infoToLog); }
public bool logout() { if (_id < 1) { return(false); } string strSQL = "SELECT COUNT(1) FROM TblUserLog WHERE userLogID=" + _id; if (_conn.executeData(strSQL, Common.getCaller())) { DbDataReader dr = _conn.Reader; if (dr.HasRows) { dr.Read(); int rowCount = dr.GetInt32(0); dr.Close(); dr.Dispose(); if (rowCount < 1) { return(false); } strSQL = "SELECT sysdate FROM dual"; if (_conn.executeData(strSQL, Common.getCaller())) { dr = _conn.Reader; if (dr.HasRows) { dr.Read(); _end = dr.GetDateTime(0); dr.Close(); dr.Dispose(); strSQL = "UPDATE TblUserLog SET userLogEnd=" + _conn.formatDateTime(_end) + " WHERE userLogID=" + _id; if (_conn.executeSQL(strSQL, Common.getCaller())) { LogDetail detail = new LogDetail(this); detail.MenuID = 0; detail.SQLText = "Application log out."; if (detail.save()) { _details.Add(detail); return(true); } else { return(false); } } else { return(false); } } dr.Close(); dr.Dispose(); return(false); } } dr.Close(); dr.Dispose(); } return(false); }
public async Task InsertDetail(LogDetailViewModel logDetailViewModel) { var logDetail = new LogDetail(logDetailViewModel.LogId, logDetailViewModel.RepositoryName, logDetailViewModel.Commits); await _logRepository.InsertDetail(logDetail); }
private void Log(string methodName, RouteData routeData) { string username = HttpContext.Current.User.Identity.GetUserName(); string user_id = HttpContext.Current.User.Identity.GetUserId(); var controllerName = routeData.Values["controller"]; var actionName = routeData.Values["action"]; string ip = HttpContext.Current.Request.UserHostAddress; var timestamp = HttpContext.Current.Timestamp.ToString(); var status = HttpContext.Current.Request.Params; var path = HttpContext.Current.Request.Path; var session_id = HttpContext.Current.Session.SessionID; string[] parameters = new string[] { }; string[] src = new string[] { "__RequestVerificationToken", "RememberMe", "Username", "Password", "ASP.NET_SessionId", "ai_user", "HTTP_REFERER", "HTTP_ORIGIN", "HTTP_CONTENT_LENGTH", "HTTP_CONTENT_LENGTH", "HTTP_CONTENT_TYPE", "HTTP_CACHE_CONTROL", ".ASPXAUTH", ".AspNet.ApplicationCookie", "ALL_HTTP", "ALL_RAW", "APPL_MD_PATH", "APPL_PHYSICAL_PATH", "AUTH_TYPE", "AUTH_USER", "AUTH_PASSWORD", "LOGON_USER", "REMOTE_USER", "CERT_COOKIE", "CERT_FLAGS", "CERT_ISSUER", "CERT_KEYSIZE", "CERT_SECRETKEYSIZE", "CERT_SERIALNUMBER", "CERT_SERVER_ISSUER", "CERT_SERVER_SUBJECT", "CERT_SUBJECT", "CONTENT_LENGTH", "CONTENT_TYPE", "GATEWAY_INTERFACE", "HTTPS", "HTTPS_KEYSIZE", "HTTPS_SECRETKEYSIZE", "HTTPS_SERVER_ISSUER", "HTTPS_SERVER_SUBJECT", "INSTANCE_ID", "INSTANCE_META_PATH", "LOCAL_ADDR", "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING", "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_PORT", "REQUEST_METHOD", "SCRIPT_NAME", "SERVER_NAME", "SERVER_PORT", "SERVER_PORT_SECURE", "SERVER_PROTOCOL", "SERVER_SOFTWARE", "URL", "HTTP_CONNECTION", "HTTP_ACCEPT", "HTTP_ACCEPT_ENCODING", "HTTP_ACCEPT_LANGUAGE", "HTTP_COOKIE", "HTTP_HOST", "HTTP_USER_AGENT", "HTTP_UPGRADE_INSECURE_REQUESTS" }; Dictionary <string, string> finalToDumpToDB = new Dictionary <string, string>(); foreach (string keyval in status.Keys) { bool isToAdd = true; foreach (string _src in src) { if (_src.ToString() == keyval.ToString()) { isToAdd = false; } } if (isToAdd) { finalToDumpToDB.Add(keyval, status[keyval]); parameters = finalToDumpToDB.Values.ToArray(); } } // var message = String.Format("Date: {0} | Username: {1} | IP Addresss: {2} | Path: /{3}/{4} | RequestType: {5} ", timestamp, username, ip, controllerName, actionName, methodName); //var message = String.Format("{0} PATH: /{1}/{2}. USERNAME: {3} IP ADDRESS:{4} DATE: {5} | {6}", methodName, controllerName, actionName, username,ip, timestamp); //Debug.WriteLine(message, "Log"); // Enter db using (var dbContext = new LogTestDBEntities7()) { var logData = dbContext.LogDatas.SingleOrDefault(s => s.SID == session_id); if (logData == null) { logData = new LogData(); logData.IP = ip; logData.UID = user_id; logData.SID = session_id; // } string DBParameters = string.Concat(parameters); //dbContext.LogDatas.Add(); var logDetails = new LogDetail(); logDetails.Timestamp = timestamp; logDetails.SID = session_id; logDetails.Details = path; logDetails.Queries = DBParameters; logData.LogDetails.Add(logDetails); // dbContext.LogDatas.Add(logData); dbContext.SaveChanges(); } }
public static void WritePerf(LogDetail infoToLog) { _perfLogger.Write(LogEventLevel.Information, "{@LogDetail}", infoToLog); }
static void Main(string[] args) { LogDetail logDetail = GetLogDetail("Starting application"); Logger.WriteDiagnosticLog(logDetail); var perfTracker = new PerformanceTracker("FullLogging.Console_Execution", string.Empty, logDetail.UserName, logDetail.Location, logDetail.Product, logDetail.Layer); //try //{ // var forcedException = new Exception("Something bad has happened!"); // forcedException.Data.Add("input param", "nothing to see here"); // throw forcedException; //} //catch (Exception ex) //{ // logDetail = GetLogDetail(string.Empty, ex); // Logger.WriteErrorLog(logDetail); //} var fullLoggingConnection = ConfigurationManager.ConnectionStrings["FullLoggingConnection"].ToString(); using (var db = new SqlConnection(fullLoggingConnection)) { db.Open(); try { //RAW ADO.NET //var adoCommand = new SqlCommand("uspCreateCustomer", db); //adoCommand.CommandType = System.Data.CommandType.StoredProcedure; //adoCommand.Parameters.Add(new SqlParameter("@Name", "asdadsadasdadsadadasdsad")); //adoCommand.Parameters.Add(new SqlParameter("@TotalPurchases", 12000)); //adoCommand.Parameters.Add(new SqlParameter("@TotalReturns", 100.50M)); //adoCommand.ExecuteNonQuery(); var customADO = new StoreProcedure(db, "uspCreateCustomer"); customADO.AddParameter("@Name", "stadasdasudahdusahdua"); customADO.AddParameter("@TotalPurchases", 12000); customADO.AddParameter("@TotalReturns", 100.50M); customADO.ExecuteNonQuery(); } catch (Exception ex) { var exceptionLogDetail = GetLogDetail(string.Empty, ex); Logger.WriteErrorLog(exceptionLogDetail); } } logDetail = GetLogDetail("used full logging console."); Logger.WriteUsageLog(logDetail); logDetail = GetLogDetail("Stopping app"); Logger.WriteDiagnosticLog(logDetail); perfTracker.Stop(); }
public static void WriteUsage(LogDetail infoToLog) { _usageLogger.Write(LogEventLevel.Information, "{@LogDetail}", infoToLog); }
public bool login(string username, string machineID) { if (Connection.formatValue(username) == "") { return(false); } if (Connection.formatValue(machineID) == "") { return(false); } string strSQL = "SELECT sysdate FROM dual"; if (_conn.executeData(strSQL, Common.getCaller())) { DbDataReader dr = _conn.Reader; if (dr.HasRows) { dr.Read(); _start = dr.GetDateTime(0); dr.Close(); dr.Dispose(); strSQL = "SELECT sqcUserLogID.nextVal FROM dual"; if (_conn.executeData(strSQL, Common.getCaller())) { dr = _conn.Reader; if (dr.HasRows) { dr.Read(); _id = dr.GetInt32(0); dr.Close(); dr.Dispose(); strSQL = "INSERT INTO TblUserLog VALUES(" + _id + ", '" + Connection.formatValue(username) + "', '" + Connection.formatValue(machineID) + "', to_date('" + _start.ToString("yyyy/MM/ss HH:mm:ss") + "', 'yyyy/mm/dd hh24:mi:ss'), NULL)"; if (_conn.executeSQL(strSQL, Common.getCaller())) { _details.Clear(); LogDetail detail = new LogDetail(this); detail.MenuID = 0; detail.SQLText = "Application log in"; if (detail.save()) { _details.Add(detail); return(true); } else { return(false); } } else { return(false); } } dr.Close(); dr.Dispose(); } } dr.Close(); dr.Dispose(); } return(false); }
private void Log(string methodName, RouteData routeData) { string username = HttpContext.Current.User.Identity.GetUserName(); string user_id = HttpContext.Current.User.Identity.GetUserId(); var controllerName = routeData.Values["controller"]; var actionName = routeData.Values["action"]; string ip = HttpContext.Current.Request.UserHostAddress; var timestamp = HttpContext.Current.Timestamp.ToString(); var status = HttpContext.Current.Request.Params; var path = HttpContext.Current.Request.Path; var session_id = HttpContext.Current.Session.SessionID; string[] parameters = new string[] { }; string[] src = new string[] { "__RequestVerificationToken","RememberMe", "Username","Password","ASP.NET_SessionId","ai_user","HTTP_REFERER","HTTP_ORIGIN","HTTP_CONTENT_LENGTH", "HTTP_CONTENT_LENGTH", "HTTP_CONTENT_TYPE", "HTTP_CACHE_CONTROL",".ASPXAUTH", ".AspNet.ApplicationCookie", "ALL_HTTP", "ALL_RAW", "APPL_MD_PATH", "APPL_PHYSICAL_PATH", "AUTH_TYPE", "AUTH_USER", "AUTH_PASSWORD", "LOGON_USER", "REMOTE_USER", "CERT_COOKIE", "CERT_FLAGS", "CERT_ISSUER", "CERT_KEYSIZE", "CERT_SECRETKEYSIZE", "CERT_SERIALNUMBER", "CERT_SERVER_ISSUER", "CERT_SERVER_SUBJECT", "CERT_SUBJECT", "CONTENT_LENGTH", "CONTENT_TYPE", "GATEWAY_INTERFACE", "HTTPS", "HTTPS_KEYSIZE", "HTTPS_SECRETKEYSIZE", "HTTPS_SERVER_ISSUER", "HTTPS_SERVER_SUBJECT", "INSTANCE_ID", "INSTANCE_META_PATH", "LOCAL_ADDR", "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING", "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_PORT", "REQUEST_METHOD", "SCRIPT_NAME", "SERVER_NAME", "SERVER_PORT", "SERVER_PORT_SECURE", "SERVER_PROTOCOL", "SERVER_SOFTWARE", "URL", "HTTP_CONNECTION", "HTTP_ACCEPT", "HTTP_ACCEPT_ENCODING", "HTTP_ACCEPT_LANGUAGE", "HTTP_COOKIE", "HTTP_HOST", "HTTP_USER_AGENT", "HTTP_UPGRADE_INSECURE_REQUESTS" }; Dictionary<string, string> finalToDumpToDB = new Dictionary<string, string>(); foreach (string keyval in status.Keys) { bool isToAdd = true; foreach (string _src in src) { if (_src.ToString() == keyval.ToString()) isToAdd = false; } if (isToAdd) { finalToDumpToDB.Add(keyval, status[keyval]); parameters = finalToDumpToDB.Values.ToArray(); } } // var message = String.Format("Date: {0} | Username: {1} | IP Addresss: {2} | Path: /{3}/{4} | RequestType: {5} ", timestamp, username, ip, controllerName, actionName, methodName); //var message = String.Format("{0} PATH: /{1}/{2}. USERNAME: {3} IP ADDRESS:{4} DATE: {5} | {6}", methodName, controllerName, actionName, username,ip, timestamp); //Debug.WriteLine(message, "Log"); // Enter db using(var dbContext = new LogTestDBEntities7()) { var logData = dbContext.LogDatas.SingleOrDefault(s => s.SID == session_id); if (logData == null) { logData = new LogData(); logData.IP = ip; logData.UID = user_id; logData.SID = session_id; // } string DBParameters = string.Concat(parameters); //dbContext.LogDatas.Add(); var logDetails = new LogDetail(); logDetails.Timestamp = timestamp; logDetails.SID = session_id; logDetails.Details = path; logDetails.Queries = DBParameters; logData.LogDetails.Add(logDetails); // dbContext.LogDatas.Add(logData); dbContext.SaveChanges(); } }