public void Log(string message, LogMessageLevel level) { SqlConnection cnn = null; SqlCommand cmd = null; try { cnn = new SqlConnection (ConfigurationManager.AppSettings ["ConnectionString"]); cmd = new SqlCommand (); cmd.Connection = cnn; cmd.CommandText = _commandText; cmd.Parameters.Add (new SqlParameter ("@message", message)); cmd.Parameters.Add (new SqlParameter ("@level", ((int) level) + 1)); cmd.ExecuteNonQuery(); } catch { throw; } finally { if (cmd != null) { cmd = null; } if (cnn != null) { if (cnn.State != ConnectionState.Closed) { cnn.Close (); } cnn = null; } } }
protected internal LogMessage(LogMessageState state, LogMessageLevel level, string message, object[] args) { this.State = state; this.Level = level; this.MessageFormat = message; this.MessageFormatArgs = args; }
void ILogRepository.Log(string message, LogMessageLevel level) { // Optimized switch testing for most likely level in production scenario first followed by less common levels then debug levels. // Log4Net level hierarchy is: DEBUG < INFO < WARN < ERROR < FATAL. // Each log4net setting logs its own and lower levels in the hierarchy - e.g. DEBUG logs all levels, FATAL only logs Fatal level. switch (level) { case LogMessageLevel.Warning: // Test first as its most likely production setting and should occur more often than higher levels. _log.Warn(message); break; case LogMessageLevel.Error: _log.Error(message); break; case LogMessageLevel.Fatal: _log.Fatal(message); break; case LogMessageLevel.Verbose: _log.Info(message); break; case LogMessageLevel.Debug: _log.Debug(message); break; default: _log.Info(message); break; } }
public void Log(string message, LogMessageLevel level) { using (StreamWriter buffer = new StreamWriter (GetFilename (), true)) { buffer.WriteLine (message); buffer.Flush (); buffer.Close (); } }
/// <summary> /// This is called whenever the log recieves a message and is about to write it out /// </summary> /// <param name="message">The message to be logged</param> /// <param name="lml">The message level the log is using</param> /// <param name="maskDebug">If we are printing to the console or not</param> /// <param name="logName">the name of this log (so you can have several listeners for different logs, and identify them)</param> public LogListenerEventArgs(string message, LogMessageLevel lml, bool maskDebug, string logName) : base() { this.Message = message; this.Level = lml; this.MaskDebug = maskDebug; this.LogName = logName; }
public void LogMessage(string message, LogMessageLevel level) { if (!string.IsNullOrEmpty (message)) { foreach (ILogger logger in Loggers) { if (logLevel [(int)level] && logOutput [(int)logger.GetOutputType ()]) { logger.Log (message, level); } } } }
public void LogMessage(string message, LogMessageLevel level) { if (level == LogMessageLevel.Error) { Console.Error.WriteLine(message); } else { Console.WriteLine(message); } }
/// <inheritdoc/> public override void Log(LogMessageLevel level, string message, params object[] messageArgs) { switch (level) { case LogMessageLevel.Message: LogMessage(MessageImportance.High, message, messageArgs); break; case LogMessageLevel.Warning: LogWarning(message, messageArgs); break; case LogMessageLevel.Error: LogError(message, messageArgs); break; default: LogMessage(MessageImportance.High, message, messageArgs); break; } }
/// <summary> /// Add a logging message to the progress window. /// </summary> /// <remarks> /// This method can be called from worker thread. /// </remarks> public void AddMessage(LogMessageLevel level, string message) { if (!_uiDispatcher.CheckAccess()) { _uiDispatcher.BeginInvoke(new Action <LogMessageLevel, string>(AddMessage), level, message); return; } if (IsOpen) { Brush messageBrush; // select message color based on LogMessageLevel value. // these colors match the colors in the console, which are set in MyHostUI.cs switch (level) { case LogMessageLevel.Debug: messageBrush = Brushes.DarkGray; break; case LogMessageLevel.Error: messageBrush = Brushes.Red; break; case LogMessageLevel.Warning: messageBrush = Brushes.Magenta; break; default: messageBrush = Brushes.Black; break; } _currentWindow.AddMessage(message, messageBrush); } else { throw new InvalidOperationException(); } }
/// <summary> /// Write a message to the log. /// </summary> /// <param name="level">Importance of this logged message.</param> /// <param name="maskDebug">If true, debug output will not be written.</param> /// <param name="message">Message to write, which can include string formatting tokens.</param> /// <param name="substitutions"> /// When message includes string formatting tokens, these are the values to /// inject into the formatted string. /// </param> public void Write(LogMessageLevel level, bool maskDebug, string message, params object[] substitutions) { if (_isDisposed) { return; } if (message == null) { throw new ArgumentNullException("The log message cannot be null"); } if (((int)logLevel + (int)level) > LogThreshold) { return; //too verbose a message to write } // construct the log message if (substitutions != null && substitutions.Length > 0) { message = string.Format(message, substitutions); } // write the the debug output if requested if (debugOutput && !maskDebug) { System.Diagnostics.Debug.WriteLine(message); } if (writer != null && writer.BaseStream != null) { // prepend the current time to the message message = string.Format("[{0}] {1}", DateTime.Now.ToString("hh:mm:ss"), message); // write the message and flush the buffer writer.WriteLine(message); //writer auto-flushes } FireMessageLogged(level, maskDebug, message); }
/// <summary> /// LogMessage(string msg) /// Timestamps a message with the current time and inserts it at the head of the message log /// Can be called from any thread /// </summary> /// <param name="msg">Message string to log</param> /// <param name="type">see LogMessageType [INFO]</param> /// <param name="isLogToFile">true=>write to log file [true]</param> /// <param name="level">see LogMessageLevel [INFO]</param> static public void LogMessage(string msg, LogMessageType type = LogMessageType.MISC, bool isLogToFile = true, LogMessageLevel level = LogMessageLevel.INFO) { var newLogEntry = new LogMessage(msg, type); if (messages == null) { throw new NullReferenceException(); } if (isLogToFile == true) { string logMsgWithType = String.Format("[{0}]-{1}", type.ToString(), msg); switch (level) { case LogMessageLevel.DEBUG: Loggers.log.Debug(logMsgWithType); break; case LogMessageLevel.ERROR: Loggers.log.Error(logMsgWithType); break; case LogMessageLevel.WARN: Loggers.log.Warn(logMsgWithType); break; default: Loggers.log.Info(logMsgWithType); break; } } // Insert message at the head of the log so it shows up at the top. // messages.Insert(0, newLogEntry); // Can be called from any thread UIThread.Update(() => { messages.Insert(0, newLogEntry); }); }
/// <summary> /// Write a message to the log. /// </summary> /// <param name="level">Importance of this logged message.</param> /// <param name="maskDebug">If true, debug output will not be written.</param> /// <param name="message">Message to write, which can include string formatting tokens.</param> /// <param name="substitutions"> /// When message includes string formatting tokens, these are the values to /// inject into the formatted string. /// </param> private void Write(LogMessageLevel level, bool maskDebug, string message, params object[] substitutions) { switch (level) { case LogMessageLevel.Trivial: if (substitutions.Length > 0) { log.DebugFormat(message, substitutions); } else { log.Debug(message); } break; case LogMessageLevel.Normal: if (substitutions.Length > 0) { log.InfoFormat(message, substitutions); } else { log.Info(message); } break; case LogMessageLevel.Critical: if (substitutions.Length > 0) { log.ErrorFormat(message, substitutions); } else { log.Error(message); } break; } }
/// <summary> /// Add a logging message to the progress window. /// </summary> /// <remarks> /// This method can be called from worker thread. /// </remarks> public void AddMessage(LogMessageLevel level, string message) { if (!_uiDispatcher.CheckAccess()) { _uiDispatcher.BeginInvoke(new Action<LogMessageLevel, string>(AddMessage), level, message); return; } if (IsOpen) { Brush messageBrush; // select message color based on LogMessageLevel value. // these colors match the colors in the console, which are set in MyHostUI.cs switch (level) { case LogMessageLevel.Debug: messageBrush = Brushes.DarkGray; break; case LogMessageLevel.Error: messageBrush = Brushes.Red; break; case LogMessageLevel.Warning: messageBrush = Brushes.Magenta; break; default: messageBrush = Brushes.Black; break; } _currentWindow.AddMessage(message, messageBrush); } else { throw new InvalidOperationException(); } }
public void LogMessage(string message, LogMessageLevel level) { Console.WriteLine(message); }
private void DefaultLog_MessageLogged(string message, LogMessageLevel lml, bool maskDebug, string logName) { log(lml.ToString() + ": " + message); }
/// <summary> /// Executes the task. /// </summary> /// <returns>true if successful</returns> public override bool Execute() { string errorCode = null; LogMessageLevel errorLevel = FailOnError ? LogMessageLevel.Error : LogMessageLevel.Warning; AssemblyInfoData asmInfo = default; string assemblyInfoPath = null; AssemblyVersion = MessageCodes.ErrorString; if (this.BuildEngine != null) { Logger = new LogWrapper(Log, GetType().Name); } else { Logger = new MockTaskLogger(GetType().Name); } try { string assemblyFileMsg = ""; if (string.IsNullOrWhiteSpace(AssemblyInfoPath)) { assemblyInfoPath = Path.Combine("Properties", "AssemblyInfo.cs"); } else { assemblyInfoPath = AssemblyInfoPath; } try { asmInfo = ParseAssembly(assemblyInfoPath, FailOnError); AssemblyVersion = asmInfo.AssemblyVersion; } catch (FileNotFoundException ex) { if (FailOnError) { errorCode = MessageCodes.GetAssemblyInfo.AssemblyInfoNotFound; throw; } else { Logger.LogError(ex.Message); } } assemblyFileMsg = " in " + assemblyInfoPath; if (AssemblyVersion == null || AssemblyVersion == ErrorString || AssemblyVersion.Length == 0) { Logger.LogError("AssemblyVersion could not be determined."); return(false); } return(true); } catch (ParsingException ex) { if (string.IsNullOrEmpty(errorCode)) { errorCode = MessageCodes.GetAssemblyInfo.GeneralFailure; } if (BuildEngine != null) { int line = BuildEngine.LineNumberOfTaskNode; int column = BuildEngine.ColumnNumberOfTaskNode; Logger.LogError(null, errorCode, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, ex.Message); } else { Logger.LogError(null, errorCode, null, null, ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber, ex.Message); } return(false); } catch (Exception ex) { if (string.IsNullOrEmpty(errorCode)) { errorCode = MessageCodes.GetAssemblyInfo.GeneralFailure; } if (BuildEngine != null) { int line = BuildEngine.LineNumberOfTaskNode; int column = BuildEngine.ColumnNumberOfTaskNode; Logger.LogError(null, errorCode, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, ex.Message); } else { Logger.LogError(null, errorCode, null, null, 0, 0, 0, 0, $"{ex.Message}"); } return(false); } }
public BillingResult Post([FromBody] BillingModel model) { HttpContext.Current.Server.ScriptTimeout = 1800; if (model == null) { throw new ArgumentNullException("model"); } DateTime start = DateTime.Now; int clientId = (model.ClientID == 0) ? -1 : model.ClientID; bool success = true; int count; string message = string.Empty; string subject = "Data.Controllers.ApiBillingController.Post"; LogMessageLevel level = LogMessageLevel.Info; ProcessResult result; string context = "Data.Controllers.ApiBillingController.Post"; if (model.StartPeriod != DateTime.MinValue) { if (model.EndPeriod == DateTime.MinValue) { model.EndPeriod = model.StartPeriod.AddMonths(1); } using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnSselData"].ConnectionString)) { conn.Open(); BillingDataProcessStep1 step1 = new BillingDataProcessStep1(new Step1Config { Connection = conn, ClientID = clientId, IsTemp = model.IsTemp, Period = model.StartPeriod, Now = DateTime.Now, Context = context }); BillingDataProcessStep2 step2; BillingDataProcessStep3 step3; BillingDataProcessStep4Subsidy step4; switch (model.Command) { case "tool-data-clean": result = new WriteToolDataCleanProcess(new WriteToolDataCleanConfig { Connection = conn, StartDate = model.StartPeriod, EndDate = model.EndPeriod, ClientID = clientId, Context = context }).Start(); message += result.LogText; break; case "room-data-clean": result = new WriteRoomDataCleanProcess(new WriteRoomDataCleanConfig { Connection = conn, StartDate = model.StartPeriod, EndDate = model.EndPeriod, ClientID = clientId, RoomID = model.RoomID, Context = context }).Start(); message += result.LogText; break; case "store-data-clean": result = new WriteStoreDataCleanProcess(new WriteStoreDataCleanConfig { Connection = conn, StartDate = model.StartPeriod, EndDate = model.EndPeriod, ClientID = clientId, Context = context }).Start(); message += result.LogText; break; case "tool-data": result = new WriteToolDataProcess(new WriteToolDataConfig { Connection = conn, Period = model.StartPeriod, ClientID = clientId, ResourceID = model.ResourceID, Context = context }).Start(); message += result.LogText; break; case "room-data": result = new WriteRoomDataProcess(new WriteRoomDataConfig { Connection = conn, Period = model.StartPeriod, ClientID = clientId, RoomID = model.RoomID, Context = context }).Start(); message += result.LogText; break; case "store-data": result = new WriteStoreDataProcess(new WriteStoreDataConfig { Connection = conn, Period = model.StartPeriod, ClientID = clientId, ItemID = model.ItemID, Context = context }).Start(); message += result.LogText; break; case "tool-billing-step1": result = step1.PopulateToolBilling(); message += result.LogText; break; case "room-billing-step1": result = step1.PopulateRoomBilling(); message += result.LogText; break; case "store-billing-step1": result = step1.PopulateStoreBilling(); message += result.LogText; break; case "tool-billing-step2": step2 = new BillingDataProcessStep2(conn); count = step2.PopulateToolBillingByAccount(model.StartPeriod, clientId); message += $"Tool Step2 By Account: count = {count}"; count = step2.PopulateToolBillingByToolOrg(model.StartPeriod, clientId); message += $"{Environment.NewLine}Tool Step2 By Tool Org: count = {count}"; break; case "room-billing-step2": step2 = new BillingDataProcessStep2(conn); count = step2.PopulateRoomBillingByAccount(model.StartPeriod, clientId); message += $"Room Step2 By Account: count = {count}"; count = step2.PopulateRoomBillingByRoomOrg(model.StartPeriod, clientId); message += $"{Environment.NewLine}Room Step2 By Room Org: count = {count}"; break; case "store-billing-step2": step2 = new BillingDataProcessStep2(conn); count = step2.PopulateStoreBillingByAccount(model.StartPeriod, clientId); message += $"Store Step2 By Account: count = {count}"; count = step2.PopulateStoreBillingByItemOrg(model.StartPeriod, clientId); message += $"{Environment.NewLine}Store Step2 By Item Org: count = {count}"; break; case "tool-billing-step3": step3 = new BillingDataProcessStep3(conn); count = step3.PopulateToolBillingByOrg(model.StartPeriod, clientId); message += $"Tool Step3 By Org: count = {count}"; break; case "room-billing-step3": step3 = new BillingDataProcessStep3(conn); count = step3.PopulateRoomBillingByOrg(model.StartPeriod, clientId); message += $"Room Step3 By Org: count = {count}"; break; case "store-billing-step3": step3 = new BillingDataProcessStep3(conn); count = step3.PopulateStoreBillingByOrg(model.StartPeriod); message += $"Store Step3 By Org: count = {count}"; break; case "subsidy-billing-step4": step4 = new BillingDataProcessStep4Subsidy(new Step4Config { Connection = conn, Period = model.StartPeriod, ClientID = clientId, Context = context }); result = step4.PopulateSubsidyBilling(); message += result.LogText; break; case "subsidy-distribution": step4 = new BillingDataProcessStep4Subsidy(new Step4Config { Connection = conn, Period = model.StartPeriod, ClientID = clientId, Context = context }); step4.DistributeSubsidyMoneyEvenly(); message += "Subsidy distribution: complete"; break; case "finalize-data-tables": result = DataTableManager.Create(Provider).Finalize(model.StartPeriod); message += result.LogText; break; default: success = false; message += $"Unknown command: {model.Command}"; level = LogMessageLevel.Error; break; } } } else { success = false; message += $"Missing parameter: StartPeriod [{model.StartPeriod:yyyy-MM-dd HH:mm:ss}]"; level = LogMessageLevel.Error; } Log.Write(level, subject, message, null); DateTime end = DateTime.Now; return(new BillingResult() { Success = success, Command = model.Command, Description = subject, StartDate = start, EndDate = end, TimeTaken = (end - start).TotalSeconds, LogText = message }); }
/// <inheritdoc/> public void Log(string subcategory, string code, string helpKeyword, string file, FilePosition position, LogMessageLevel level, string message, params object[] messageArgs) => Log(subcategory, code, helpKeyword, file, position.StartLine, position.StartColumn, position.EndLine, position.EndColumn, level, message, messageArgs);
public void LogMessage(string message, LogMessageLevel level) { throw new System.NotImplementedException(); }
public LoggerBuilder AddOutputProvider(ILoggerOutputProvider outputProvider, LogMessageLevel messageLevel = LogMessageLevel.All) { currentLogger.OutputProviders[(int)messageLevel].Add(outputProvider); return(this); }
private void FireMessageLogged( LogMessageLevel level, bool maskDebug, string message ) { // Now fire the MessageLogged event if( this.MessageLogged != null ) { LogListenerEventArgs args = new LogListenerEventArgs( message, level, maskDebug, this.mLogName ); this.MessageLogged( this, args ); } }
private static LogMessage Create(LogMessageLevel level, string message, object[] args) { return(new LogMessage(LogMessageState.REQUEST, level, message, args)); }
private void DefaultLog_MessageLogged(string message, LogMessageLevel lml, bool maskDebug, string logName) { log(lml.ToString() + ": " + message); }
/// <summary> /// Производит запись в журнал сообщения /// </summary> /// <param name="msg">Сообщение</param> /// <param name="level">Уровень сообщения</param> public static void Log(string msg, LogMessageLevel level = LogMessageLevel.Info) { Log(msg, string.Empty, level); }
/// <summary> /// Logs the provided message with a reference to the specified log level. /// </summary> /// <param name="level"> The log or severity level to associate with the message. </param> /// <param name="messageToLog"> The content to be emitted to the log. </param> public void Log(LogMessageLevel level, string messageToLog) { Trace.WriteLine($"{level.ToString()}: {messageToLog}", this.name); }
public static LoggerBuilder AddConsoleProvider(this LoggerBuilder builder, LogMessageLevel messageLevel = LogMessageLevel.All) { builder.AddOutputProvider(new LoggerOutputConsoleProvider(), messageLevel); return(builder); }
public static void LogException(Exception ex, LogMessageLevel level) { LogException(ex, level, ""); }
public LoggerBuilder ShowHeader(LogMessageLevel messageLevel = LogMessageLevel.All, bool show = true) { currentLogger.ShowHeader[(int)messageLevel] = show; return(this); }
internal LogMessage(LogMessageState state, LogMessageLevel level, string message, object[] args) : base(state, level, message, args) { }
public override void LogMessage(string message, LogMessageLevel level) { _output.WriteLine($"{level}:: {message}"); }
/// <inheritdoc/> public void Log(string subcategory, string code, string helpKeyword, string file, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber, LogMessageLevel level, string message, params object[] messageArgs) { switch (level) { case LogMessageLevel.Message: LogMessage(subcategory, code, helpKeyword, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, MessageImportance.High, message, messageArgs); break; case LogMessageLevel.Warning: LogWarning(subcategory, code, helpKeyword, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, messageArgs); break; case LogMessageLevel.Error: LogError(subcategory, code, helpKeyword, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, messageArgs); break; default: LogMessage(subcategory, code, helpKeyword, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, MessageImportance.High, message, messageArgs); break; } }
public static void Log(LogMessageLevel level, string message, TimeSpan?duration = null) { Log(new LogMessage(level, message, duration)); }
/// <inheritdoc/> public abstract void Log(LogMessageLevel level, string message, params object[] messageArgs);
/// <summary> /// Write a message to the log. /// </summary> /// <param name="level">Importance of this logged message.</param> /// <param name="maskDebug">If true, debug output will not be written.</param> /// <param name="message">Message to write, which can include string formatting tokens.</param> /// <param name="substitutions"> /// When message includes string formatting tokens, these are the values to /// inject into the formatted string. /// </param> public void Write( LogMessageLevel level, bool maskDebug, string message, params object[] substitutions ) { if ( _isDisposed ) return; if ( message == null ) throw new ArgumentNullException( "The log message cannot be null" ); if ( ( (int)logLevel + (int)level ) > LogThreshold ) return; //too verbose a message to write // construct the log message if ( substitutions != null && substitutions.Length > 0 ) { message = string.Format( message, substitutions ); } // write the the debug output if requested if ( debugOutput && !maskDebug ) { System.Diagnostics.Debug.WriteLine( message ); } if ( writer != null && writer.BaseStream != null ) { // prepend the current time to the message message = string.Format( "[{0}] {1}", DateTime.Now.ToString( "hh:mm:ss" ), message ); // write the message and flush the buffer writer.WriteLine( message ); //writer auto-flushes } }
/// <summary> /// Write a message to the log. /// </summary> /// <param name="level">Importance of this logged message.</param> /// <param name="maskDebug">If true, debug output will not be written.</param> /// <param name="message">Message to write, which can include string formatting tokens.</param> /// <param name="substitutions"> /// When message includes string formatting tokens, these are the values to /// inject into the formatted string. /// </param> private void Write(LogMessageLevel level, bool maskDebug, string message, params object[] substitutions) { switch (level) { case LogMessageLevel.Trivial: if (substitutions.Length > 0) log.DebugFormat(message, substitutions); else log.Debug(message); break; case LogMessageLevel.Normal: if (substitutions.Length > 0) log.InfoFormat(message, substitutions); else log.Info(message); break; case LogMessageLevel.Critical: if (substitutions.Length > 0) log.ErrorFormat(message, substitutions); else log.Error(message); break; } }
private static LogMessage Create(LogMessageLevel level, string message, object[] args) { return new LogMessage(LogMessageState.REQUEST, level, message, args); }
/// <summary> /// Write a message to the log. /// </summary> /// <param name="level">Importance of this logged message.</param> /// <param name="maskDebug">If true, debug output will not be written.</param> /// <param name="message">Message to write, which can include string formatting tokens.</param> /// <param name="substitutions"> /// When message includes string formatting tokens, these are the values to /// inject into the formatted string. /// </param> public void Write(LogMessageLevel level, bool maskDebug, string message, params object[] substitutions) { DefaultLog.Write(level, maskDebug, message, substitutions); }
public static LoggerBuilder AddConsoleProvider(this LoggerBuilder builder, LogMessageLevel messageLevel = LogMessageLevel.All, ConsoleColor color = ConsoleColor.Gray) { builder.AddOutputProvider(new LoggerOutputConsoleProvider(color), messageLevel); return(builder); }
private static void messageLogged(String message, LogMessageLevel lml, IntPtr instanceHandle) { GCHandle handle = GCHandle.FromIntPtr(instanceHandle); (handle.Target as OgreLogConnection).messageLogged(message, lml); }
/// <summary> /// Write a message to the log. /// </summary> /// <param name="level">Importance of this logged message.</param> /// <param name="maskDebug">If true, debug output will not be written.</param> /// <param name="message">Message to write, which can include string formatting tokens.</param> /// <param name="substitutions"> /// When message includes string formatting tokens, these are the values to /// inject into the formatted string. /// </param> public void Write(LogMessageLevel level, bool maskDebug, string message, params object[] substitutions) { if (IsDisposed) { return; } if (message == null) { throw new ArgumentNullException("The log message cannot be null"); } if (((int)this.logLevel + (int)level) > LogThreshold) { return; //too verbose a message to write } // construct the log message if (substitutions != null && substitutions.Length > 0) { message = string.Format(message, substitutions); } // write the the debug output if requested if (this.debugOutput && !maskDebug) { #if MONO if (System.Diagnostics.Debugger.IsAttached) { System.Console.WriteLine(message); } else #endif System.Diagnostics.Debug.WriteLine(message); } #if !NETFX_CORE if (this.writer != null && this.writer.BaseStream != null) { // prepend the current time to the message message = string.Format("[{0}] {1}", DateTime.Now.ToString("hh:mm:ss"), message); // write the message and flush the buffer lock (this.writer) this.writer.WriteLine(message); //writer auto-flushes } #else if (null != this.writer) { // prepend the current time to the message message = string.Format("[{0}] {1}", DateTime.Now.ToString("hh:mm:ss"), message); this.writer.WriteString(message); this.writer.StoreAsync(); this.log.FlushAsync(); } #endif FireMessageLogged(level, maskDebug, message); }
public LogMessage(string message, LogMessageLevel level) { this.Level = level; this.Message = message; }
/// <summary> /// Write a message to the log. /// </summary> /// <param name="level">Importance of this logged message.</param> /// <param name="maskDebug">If true, debug output will not be written.</param> /// <param name="message">Message to write, which can include string formatting tokens.</param> /// <param name="substitutions"> /// When message includes string formatting tokens, these are the values to /// inject into the formatted string. /// </param> public void Write( LogMessageLevel level, bool maskDebug, string message, params object[] substitutions ) { DefaultLog.Write( level, maskDebug, message, substitutions ); }
public static extern void LogMessage( Handle self, [MarshalAs(UnmanagedType.LPStr)] String message, LogMessageLevel logLevel, [MarshalAs(UnmanagedType.I1)] bool maskDebug);
public static void LogMessage(string message, LogMessageLevel level) { LogMessage(message, level, "", ""); }
/// <summary> /// Executes the task. /// </summary> /// <returns>true if successful</returns> public override bool Execute() { string errorCode = null; LogMessageLevel errorLevel = ErrorOnMismatch ? LogMessageLevel.Error : LogMessageLevel.Warning; AssemblyInfoData asmInfo = default; string assemblyInfoPath = null; if (this.BuildEngine != null) { Logger = new LogWrapper(Log, GetType().Name); } else { Logger = new MockTaskLogger(GetType().Name); } try { if (!Util.MatchVersions(AssemblyVersion, PluginVersion)) { Logger.Log(null, MessageCodes.CompareVersions.VersionMismatch, "", assemblyInfoPath, asmInfo.AssemblyVersionPosition, errorLevel, "PluginVersion {0} does not match AssemblyVersion {1}.", PluginVersion, AssemblyVersion); if (ErrorOnMismatch) { return(false); } } return(true); } catch (VersionMatchException ex) { if (BuildEngine != null) { int line = BuildEngine.LineNumberOfTaskNode; int column = BuildEngine.ColumnNumberOfTaskNode; Logger.LogError(null, MessageCodes.CompareVersions.InvalidVersion, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, ex.Message); } else { Logger.LogError(null, MessageCodes.CompareVersions.InvalidVersion, null, null, 0, 0, 0, 0, ex.Message); } return(false); } catch (ParsingException ex) { if (string.IsNullOrEmpty(errorCode)) { errorCode = MessageCodes.CompareVersions.GeneralFailure; } if (BuildEngine != null) { int line = BuildEngine.LineNumberOfTaskNode; int column = BuildEngine.ColumnNumberOfTaskNode; Logger.LogError(null, errorCode, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, ex.Message); } else { Logger.LogError(null, errorCode, null, null, ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber, ex.Message); } return(false); } catch (Exception ex) { if (string.IsNullOrEmpty(errorCode)) { errorCode = MessageCodes.CompareVersions.GeneralFailure; } if (BuildEngine != null) { int line = BuildEngine.LineNumberOfTaskNode; int column = BuildEngine.ColumnNumberOfTaskNode; Logger.LogError(null, errorCode, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, $"Error in {GetType().Name}: {ex.Message}"); } else { Logger.LogError(null, errorCode, null, null, 0, 0, 0, 0, $"Error in {GetType().Name}: {ex.Message}"); } return(false); } }
private void VerifyLogMessage(ILogMessage logMessage, LogMessageLevel level) { logMessage.Level.Should().Be(level); logMessage.Message.Should().Be(text); }
private void LogCore(LogMessageLevel level, string message, params object[] args) { string formattedMessage = String.Format(CultureInfo.CurrentCulture, message, args); // for the dialog we ignore debug messages if (_progressWindowOpener.IsOpen && level != LogMessageLevel.Debug) { _progressWindowOpener.AddMessage(level, formattedMessage); } WriteLineToOutputWindow(formattedMessage); }
internal LogMessage(LogMessageState state, LogMessageLevel level, string message, object[] args) : base(state, level, message, args) { }