internal static void AddMessage(byte[] data, int connectionID, LogState state) { if (!MessageLoggerManager.enabled) { return; } string data2; switch (state) { case LogState.ConnectionOpen: data2 = "CONCLOSE"; break; case LogState.ConnectionClose: data2 = "CONOPEN"; break; default: data2 = Encoding.Default.GetString(data); break; } lock (MessageLoggerManager.loggedMessages.SyncRoot) { Message message = new Message(connectionID, MessageLoggerManager.GenerateTimestamp(), data2); MessageLoggerManager.loggedMessages.Enqueue(message); } }
private ConsoleColor getForegroundColor(LogState state) { ConsoleColor consoleColor = ConsoleColor.White; switch (state) { case LogState.T: { consoleColor = ConsoleColor.Gray; break; } case LogState.D: { consoleColor = ConsoleColor.Gray; break; } case LogState.I: { consoleColor = ConsoleColor.DarkGreen; break; } case LogState.W: { consoleColor = ConsoleColor.Yellow; break; } case LogState.E: { consoleColor = ConsoleColor.Red; break; } } return consoleColor; }
internal static void AddMessage(byte[] data, int connectionID, LogState state) { if (!enabled) return; string message; switch (state) { case LogState.ConnectionClose: { message = "CONOPEN"; break; } case LogState.ConnectionOpen: { message = "CONCLOSE"; break; } default: { message = System.Text.Encoding.Default.GetString(data); break; } } lock (loggedMessages.SyncRoot) { Message loggedMessage = new Message(connectionID, GenerateTimestamp(), message); loggedMessages.Enqueue(loggedMessage); } }
private void Output(LogState state, string format, params object[] args) { lock (LockObject) { DateTime now = DateTime.Now; string message = args.Length == 0 ? format : string.Format(format, args); string output = string.Format("[{0}], [{1}] : {2}", now.ToString(), state.ToString(), message); WriteLog(output); } }
public ActionResult Index(SortCriteria? sortCriteria, LogState? logState) { var result = new SortedLogModel(); if (sortCriteria != null) { result.SortCriteria = (SortCriteria) sortCriteria; } if (logState != null) { result.CurrentState = logState; } result.Sort(facade.GetLogGateway((LoggedInModel)Session["LoginModel"]).GetAll()); return View(result); }
/// <summary> /// Logs directly in the from the logger created file /// Ignores Logs which are unter the LogState which is defined in the configuration. /// </summary> /// <param name="logMessage">The message to show in the log</param> /// <param name="state">The state to classify the information level</param> public static void Log(string logMessage, LogState state = LogState.INFO) { if (Configuration.logLevel <= state) { try { string logLevel = string.Empty; logLevel = GetStateString(state); string temp = "\r\n" + DateTime.Now.ToString("s") + " \t- " + logLevel + " - " + logMessage; Debug.WriteLine(temp); writer.WriteLine(temp); } catch (Exception ex) { Debug.WriteLine("Writer could not created."); } //writer.FlushAsync(); } }
public static void LogTX(char ch) { using (StreamWriter writer = new StreamWriter(FilePath, true)) { if (state == LogState.Init || state == LogState.RX || DateTime.Now.Subtract(lastTXTime).TotalSeconds > 5) { lastTXTime = DateTime.Now; string text = String.Format(Environment.NewLine + "(TX) {0} : {1}", DateTime.Now.ToString(Conf.LOG_TIMESTAMP_FORMAT), ch); writer.Write(text); writer.Flush(); state = LogState.TX; } else if (state == LogState.TX) { writer.Write(ch); writer.Flush(); } } }
public static ConsoleColor GetColor(LogState pLevel) { switch (pLevel) { case LogState.None: return ConsoleColor.DarkYellow; case LogState.Info: return ConsoleColor.Green; case LogState.Warn: return ConsoleColor.Yellow; case LogState.Debug: return ConsoleColor.Magenta; case LogState.Error: return ConsoleColor.DarkRed; case LogState.Exception: return ConsoleColor.Red; default: return ConsoleColor.White; } }
public static void WriteLine(LogState pLogLevel, string pFormat, params object[] pArgs) { // if (LogLogLevel > (byte)pLogLevel) return; string header = "[" + DateTime.Now.ToShortTimeString() + "] (" + pLogLevel + ") "; string buffer = string.Format(pFormat, pArgs); Locker.WaitOne(); try { Console.ForegroundColor = GetColor(pLogLevel); if ( ((LogState)Enum.Parse(typeof(LogState), pLogLevel.ToString())).ToString() != "None" ) { Console.Write(header); } Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(buffer); if (String.IsNullOrEmpty(LogFile)) { return; } StreamWriter sw = File.AppendText(LogFile); try { sw.WriteLine(header + buffer); } finally { sw.Close(); } } finally { Locker.ReleaseMutex(); } }
/// <summary> /// This is called for each Message response we receive from the cvs server when we are /// processing the header /// </summary> public void OnMessageHeader(string message) { // First handle symbolic names substate if (logState == LogState.WANT_FILE_HEADER_SYMBOLIC_NAMES) { // symbolic names start with a tab // but we also detect space, just in case if (message.StartsWith("\t") || message.StartsWith(" ")) { // extract symbolic name and revision ExtractSymbolicName(message); } else { // this must be the end of the symbolic names logState = LogState.WANT_FILE_HEADER; // Note: we must now check for other tags that we are interested in } } if (message.StartsWith(symbolicNamesPrefix)) { // file line is of form 'symbolic names:' logState = LogState.WANT_FILE_HEADER_SYMBOLIC_NAMES; } else if (message.StartsWith(repositoryFnmPrefix)) { // file line is of form 'RCS file: <filename>' curLogFile.RepositoryFnm = message.Substring(repositoryFnmPrefix.Length); logState = LogState.WANT_FILE_HEADER; } else if (message.StartsWith(repositoryFnmPrefixWithM)) { // file line is of form 'M RCS file: <filename>' curLogFile.RepositoryFnm = message.Substring(repositoryFnmPrefixWithM.Length); logState = LogState.WANT_FILE_HEADER; } else if (message.StartsWith(workingFnmPrefix)) { // file line is of form 'Working file: <filename>' curLogFile.WorkingFnm = message.Substring(workingFnmPrefix.Length); logState = LogState.WANT_FILE_HEADER; } else if (message.StartsWith(descriptionPrefix)) { // description line is of form 'description:' // and is then optionally followed by a multi-line description logState = LogState.WANT_FILE_DESCRIPTION; } }
private void Initialise(LogState flag, bool flush) { try { lock(this) { // generate the filename & path string strFilePath = GetFilePath(flag); // if the directory doesn't already exist, create it! if(!Directory.Exists(mstrLogPath)) { Directory.CreateDirectory(mstrLogPath); } // if already accessing a file, close off the logger if(mLogStream != null) { mLogWriter.Close(); mLogStream.Close(); mLogWriter = null; mLogStream = null; } // instantiate the stream and and writer... mLogStream = new FileStream(strFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); mLogWriter = new StreamWriter(mLogStream); mLogWriter.AutoFlush = true; // point to the end of the file... mLogWriter.BaseStream.Seek(0, SeekOrigin.End); } } catch(Exception) { //EventLog.WriteEntry("WEASL", string.Format("Exception: {0} Stack: {1}", ex.Message, ex.StackTrace), EventLogEntryType.Error); } }
private string GetFilePath(LogState flag) { string strReturnValue = ""; // return value uint uiSort = 0, uiTempSort = 0; // temp sorting file index DateTime dt = DateTime.Now; // get current date time string searchPattern = // prepare search pattern dt.ToString("yyyy-MM-dd_") + mstrLogCaller + "_"; // create log directory if not available if(Directory.Exists(mstrLogPath) == false) { Directory.CreateDirectory(mstrLogPath); } // get a file list string[] strFileList = Directory.GetFiles(mstrLogPath, searchPattern + "*.LOG"); strReturnValue = mstrLogPath + searchPattern + "0.LOG"; FileInfo fi = new FileInfo(strReturnValue); // // If there are several files and this one already exists // try to fomulate a new file name // if((strFileList.Length != 0) && fi.Exists) { // loop through strFileList foreach(string strItem in strFileList) { // split file name to get ?? from 2002-12-08_STL_??.LOG string[] tmpArray = strItem.Split('_', '.'); try { if((uiTempSort = System.Convert.ToUInt32(tmpArray[tmpArray.Length - 2])) >= uiSort) { uiSort = uiTempSort; if(flag != LogState.Rollover) { strReturnValue = strItem; } else { strReturnValue = mstrLogPath + searchPattern + ++uiSort + ".LOG"; } } } catch { // // If this fails, assume the file does not exist // Can happen when somebody renamed a file and the above expodes // strReturnValue = mstrLogPath + searchPattern + "0.LOG"; } } } return strReturnValue; }
public CompileLogTracer() { _state = LogState.Startup; _words = new List<OutputWord>(); }
/// <summary> /// Get the String for the enum of LogState /// </summary> /// <param name="state"></param> /// <returns>The string of the state</returns> private static string GetStateString(LogState state) { string logLevel; switch (state) { case LogState.INFO: logLevel = "Info"; break; case LogState.TRACE: logLevel = "Trace"; break; case LogState.WARNING: logLevel = "Warning"; break; case LogState.ERROR: logLevel = "Error"; break; case LogState.FATAL: logLevel = "Fatal"; break; default: logLevel = "DEFAULT"; break; } return logLevel; }
private LogState StartRecord(string line, LogState state) { var rec = new LogRecord(); int n = line.IndexOf(']'); if (n < 2) { throw new ArgumentException(); } rec.Type = line.Substring(1, n - 1); rec.SubType = line.Substring(n + 2).Replace(":", ""); var session = this.FileSessions[this.FileSessions.Count - 1]; session.Records.Add(rec); state = LogState.InRecord; return state; }
/// <summary> /// The logger for Exceptions, normally a caught exception is just a warning /// </summary> /// <param name="logMessage">A message to put before the exception text</param> /// <param name="exception">The exception to analyise</param> /// <param name="state">Optional, normal LogState.WARNING</param> public static void LogException(string logMessage, Exception exception, LogState state = LogState.WARNING) { Log(logMessage + "\r\n" + exception.Message + "\r\n\r\n" + exception.StackTrace + "\r\n", state); }
//public abstract XmlAttribute[] GetUnhandledAttributes(); /// <summary> /// merge a document into the current. /// </summary> /// <param name="sourceDocument">the source Document</param> public void Merge(Document sourceDocument) { #region Declarations Property sourceProperty; DocumentCollection sourceCollection; #endregion // set the CRM id from the source document this.crmId = sourceDocument.crmId; // set the log state from the source document this.logState = sourceDocument.logState; // go thru each property of the current document foreach (Property prop in Properties.Values) { // if the log state is deleted clear the property if (sourceDocument.LogState == LogState.Deleted) { prop.Value = null; continue; } // if the property not part of the source documet // continue with the next property if (!sourceDocument.Properties.ContainsKey(prop.Name)) continue; // get the source property sourceProperty = sourceDocument.Properties[prop.Name]; // continue if the property was not set. Not set is different from null if (sourceProperty.NotSet) continue; // set the property prop.Value = sourceProperty.Value; } // go thru each document collection foreach (DocumentCollection coll in Collections.Values) { // continue if the document collection is not part of the source document if (!sourceDocument.Collections.ContainsKey(coll.CollectionName)) continue; // get the source collection sourceCollection = sourceDocument.Collections[coll.CollectionName]; // continue if the collection was not set. Not set is different from null if (sourceCollection.NotSet) continue; //merge the collection coll.Merge(sourceCollection); } }
private void StateLineStart(string line) { switch (_state) { case LogState.None: if (SettingsStart.IsMatch(line)) _state = LogState.Settings; break; case LogState.Startup: break; case LogState.Settings: if (!SettingsLine.IsMatch(line) && !line.StartsWith("Current") && !line.StartsWith("Name") && !line.StartsWith("-----") && !String.IsNullOrWhiteSpace(line) && !line.StartsWith("custom shadows with bounce light")) { _state = LogState.None; } break; } }
private TransactionAction LogstateToTransactionAction(LogState logState) { switch (logState) { case LogState.Created: return TransactionAction.Created; case LogState.Updated: return TransactionAction.Updated; case LogState.Deleted: return TransactionAction.Deleted; default: return TransactionAction.Created; } }
/// <summary> /// This is called for each Message response we receive from the cvs server. /// </summary> public void OnMessage(string message) { // System.Console.WriteLine(message); // for some reason the message handler is now preceeding // each message with "cvs server: " so we need to strip this off first if (message.StartsWith("cvs server: ")) { message = message.Substring(12); } // only process the lines starting with "M " if (message.StartsWith("M ")) { // Strip of the leading "M " message = message.Substring(2); if (message.StartsWith(revisionEndPrefix)) { // seperator between file and revision or between revisions if (logState == LogState.WANT_FILE_HEADER_START) { // ignore this (shouldn't happen) } else if (logState == LogState.WANT_FILE_HEADER || logState == LogState.WANT_FILE_DESCRIPTION) { // this is the seperator between te file header and the first revision } else { // seperator between revisions curLogFile.AddRevision(curLogRevision); } curLogRevision = new LogRevision(); logState = LogState.WANT_REVISION; } else if (message.StartsWith(fileEndPrefix)) { // seperator between files if (logState == LogState.WANT_FILE_HEADER_START) { // ignore this (shouldn't happen) } else if (logState == LogState.WANT_FILE_HEADER || logState == LogState.WANT_FILE_DESCRIPTION) { // file with no revisions curLogReport.AddFile(curLogFile); } else { // first add the revision curLogFile.AddRevision(curLogRevision); curLogRevision = new LogRevision(); // and now the file curLogReport.AddFile(curLogFile); } curLogFile = new LogFile(this.cvsRoot); logState = LogState.WANT_FILE_HEADER_START; } else { switch (logState) { case LogState.WANT_FILE_HEADER_START: // drop into WANT_FILE_HEADER case LogState.WANT_FILE_HEADER_SYMBOLIC_NAMES: // drop into WANT_FILE_HEADER case LogState.WANT_FILE_HEADER: OnMessageHeader(message); break; case LogState.WANT_FILE_DESCRIPTION: OnMessageDescription(message); break; case LogState.WANT_REVISION: OnMessageRevision(message); break; } } } }
/// <summary> /// Produce the report /// Alternate interface for when we are given a server cooection /// This is needed for the SharpCvsLib command line client /// </summary> public LogReport Run(ICommandConnection connection) { // read Root and Repository from local directory if (null == this.cvsRoot) { Manager manager = new Manager(localDirectory); Root root = (Root)manager.FetchSingle (localDirectory, Factory.FileType.Root); this.cvsRoot = new CvsRoot(root.FileContents); } if (null == workingDirectory) { Manager manager = new Manager(localDirectory); Repository repository = (Repository)manager.FetchSingle (localDirectory, Factory.FileType.Repository); this.workingDirectory = new WorkingDirectory(cvsRoot, localDirectory, repository.FileContents); } ILogCommand command; // Recursively add all cvs folders/files under the localDirectory System.Console.WriteLine("GNE workingDirectory.WorkingPath = {0}", workingDirectory.WorkingPath); System.Console.WriteLine("GNE localDirectory: {0}", localDirectory); // if (Directory.Exists(workingDirectory.WorkingPath)) { if (Directory.Exists(localDirectory) && File.Exists(Path.Combine(localDirectory, "Repository"))) { workingDirectory.FoldersToUpdate = FetchFiles(localDirectory); command = new LogCommand(workingDirectory, this.workingDirectory.ModuleName, null); } else { command = // GNE - this wont compile new LogCommand(workingDirectory, this.workingDirectory.ModuleName); new RLogCommand(workingDirectory, this.workingDirectory.ModuleName); } // add any date restrictions if (hasStartDate && hasEndDate) { command.AddInclusiveDateRange(startDate, endDate); } else if (hasStartDate) { command.AddInclusiveDateStart(startDate); } else if (hasEndDate) { command.AddInclusiveDateEnd(endDate); } // Initialse state machine curLogReport = new LogReport(); // this is what we are going to return to the caller curLogFile = new LogFile(this.cvsRoot); curLogRevision = new LogRevision(); logState = LogState.WANT_FILE_HEADER_START; if (connection.GetType() == typeof(CVSServerConnection)) { CVSServerConnection cvsServerConnection = (CVSServerConnection)connection; cvsServerConnection.MessageEvent.MessageEvent += new EncodedMessage.MessageHandler(OnMessage); } command.Execute(connection); // return curLogReport but clear our reference to it LogReport report = curLogReport; curLogReport = null; return report; }
private void Output(LogState state, string format, params object[] args) { DateTime now = DateTime.Now; string message = args.Length == 0 ? format : string.Format(format, args); string output = string.Format("[{0}], [{1}] : {2}", now.ToString(), state.ToString(), message); Console.ForegroundColor = getForegroundColor(state); Console.WriteLine(output); Console.ResetColor(); }
private void LineStartup(string line) { if (line.StartsWith("----- ")) { Emit(line, ConsoleColor.Gray); _state = LogState.None; } else { Emit(line, ConsoleColor.Green); } }