/// <summary> /// Writes specified log entry to log file. /// </summary> /// <param name="file">Log file.</param> /// <param name="e">Log entry to write.</param> public static void WriteLog(string file, LogEntry e) { try { using (TextDb db = new TextDb('\t')) { db.OpenOrCreate(file); //db.AppendComment("Fields: ID Time RemoteEndPoint AuthenticatedUser LogType LogText"); string logText = ""; if (e.Text != null) { logText = e.Text.Replace("\r", ""); if (logText.EndsWith("\n")) { logText = logText.Substring(0, logText.Length - 1); } } string logType = ""; if (e.EntryType == LogEntryType.Text) { logType = "xxx"; } else if (e.EntryType == LogEntryType.Read) { logType = "<<<"; } else if (e.EntryType == LogEntryType.Write) { logType = ">>>"; } foreach (string logLine in logText.Split('\n')) { db.Append(new string[] { e.ID, DateTime.Now.ToString(), e.RemoteEndPoint != null ? e.RemoteEndPoint.ToString() : "", e.UserIdentity != null ? e.UserIdentity.Name : "", logType, logLine }); } } } catch (Exception x) { Error.DumpError(x, new System.Diagnostics.StackTrace()); } }
/// <summary> /// Writes specified log entry to log file. /// </summary> /// <param name="file">Log file.</param> /// <param name="e">Log entry to write.</param> public static void WriteLog(string file,LogEntry e) { try{ using(TextDb db = new TextDb('\t')){ db.OpenOrCreate(file); //db.AppendComment("Fields: ID Time RemoteEndPoint AuthenticatedUser LogType LogText"); string logText = ""; if(e.Text != null){ logText = e.Text.Replace("\r",""); if(logText.EndsWith("\n")){ logText = logText.Substring(0,logText.Length - 1); } } string logType = ""; if(e.EntryType == LogEntryType.Text){ logType = "xxx"; } else if(e.EntryType == LogEntryType.Read){ logType = "<<<"; } else if(e.EntryType == LogEntryType.Write){ logType = ">>>"; } foreach(string logLine in logText.Split('\n')){ db.Append(new string[]{ e.ID, DateTime.Now.ToString(), e.RemoteEndPoint != null ? e.RemoteEndPoint.ToString() : "", e.UserIdentity != null ? e.UserIdentity.Name : "", logType, logLine }); } } } catch(Exception x){ Error.DumpError(x,new System.Diagnostics.StackTrace()); } }
/// <summary> /// Writes socket log to the specified log file. /// </summary> /// <param name="file">Log file.</param> /// <param name="logger">Socket logger.</param> public static void WriteLog(string file,SocketLogger logger) { try{ using(TextDb db = new TextDb('\t')){ db.OpenOrCreate(file); db.AppendComment("Fields: SessionID SessionStartTime RemoteEndPoint AuthenticatedUser LogType LogText"); foreach(SocketLogEntry logEntry in logger.LogEntries){ string logText = logEntry.Text.Replace("\r",""); if(logText.EndsWith("\n")){ logText = logText.Substring(0,logText.Length - 1); } string logType = ""; if(logEntry.Type == SocketLogEntryType.FreeText){ logType = "xxx"; } else if(logEntry.Type == SocketLogEntryType.ReadFromRemoteEP){ logType = "<<<"; } else if(logEntry.Type == SocketLogEntryType.SendToRemoteEP){ logType = ">>>"; } foreach(string logLine in logText.Split('\n')){ db.Append(new string[]{ logger.SessionID, DateTime.Now.ToString(), ConvertEx.ToString(logger.RemoteEndPoint), logger.UserName, logType, logLine }); } } } } catch(Exception x){ Error.DumpError(x,new System.Diagnostics.StackTrace()); } }