public static void Write(string message, LogLevelType level, MPAlignerConfiguration conf=null) { if ((conf==null && level>=confLogLevel) || (conf!=null && level >= conf.logLevel && conf.logLevel!= LogLevelType.NONE)) { DateTime date = DateTime.Now; string dateStr = date.ToString("yyyy-MM-dd HH:mm:ss"); if (level != LogLevelType.ERROR) { Console.Write("[MPAligner] ["); Console.Write(level.ToString()); Console.Write("] "); Console.Write(dateStr); Console.Write(" "); Console.WriteLine(message); } else { Console.Error.Write("[MPAligner] ["); Console.Error.Write(level.ToString()); Console.Error.Write("] "); Console.Error.Write(dateStr); Console.Error.Write(" "); Console.Error.WriteLine(message); } } }
public static void Write(string message, LogLevelType level, MPAlignerConfiguration conf = null) { if ((conf == null && level >= confLogLevel) || (conf != null && level >= conf.logLevel && conf.logLevel != LogLevelType.NONE)) { DateTime date = DateTime.Now; string dateStr = date.ToString("yyyy-MM-dd HH:mm:ss"); if (level != LogLevelType.ERROR) { Console.Write("[MPAligner] ["); Console.Write(level.ToString()); Console.Write("] "); Console.Write(dateStr); Console.Write(" "); Console.WriteLine(message); } else { Console.Error.Write("[MPAligner] ["); Console.Error.Write(level.ToString()); Console.Error.Write("] "); Console.Error.Write(dateStr); Console.Error.Write(" "); Console.Error.WriteLine(message); } } }
public static void WriteLog(LogLevelType LogLevel, String inLogMessage) { if ((LogLevel > LogLevelType.None) && (LogLevel <= Instance.LogLevel)) { Instance.WriteLineToLog("[" + LogLevel.ToString().ToUpper() + "] " + inLogMessage); } }
private string WriteLogEntry(List <object> curObjects, string logMessage, LogLevelType curLevel, Exception curException, string destinationMachineName, string applicationName, string uniqueId, string winUser, string tenantId) { if (string.IsNullOrEmpty(uniqueId)) { uniqueId = Guid.NewGuid().ToString(); } var nLogLevel = LogLevel.FromString(curLevel.ToString()); var curLogObject = new LogObject { Message = logMessage, CurrentDataObjects = curObjects }; string message; switch (_type) { case SerializerType.Json: message = JsonConvert.SerializeObject(curLogObject); break; case SerializerType.Xml: using (var sw = new StringWriter()) { _curSerializer.Serialize(sw, curLogObject); message = sw.ToString(); } break; default: throw new ArgumentOutOfRangeException("_type"); } var logRecord = curException != null ? new LogEventInfo(nLogLevel, null, null, message, null, curException) : new LogEventInfo(nLogLevel, null, message); logRecord.Properties["DestinationMachineName"] = destinationMachineName; logRecord.Properties["UniqueID"] = uniqueId; logRecord.Properties["TenantId"] = tenantId; if (!string.IsNullOrEmpty(applicationName)) { logRecord.Properties["AppCode"] = applicationName; } else { logRecord.Properties["AppCode"] = Process.GetCurrentProcess().ProcessName; } if (!string.IsNullOrEmpty(winUser)) { logRecord.Properties["WinUser"] = winUser; } else { logRecord.Properties["WinUser"] = System.Security.Principal.WindowsIdentity.GetCurrent().Name; } _curLogger.Log(logRecord); return(uniqueId); }
protected virtual void FormatOutput(StringBuilder stringBuilder, LogLevelType level, object message, Exception e) { if (stringBuilder == null) { throw new ArgumentNullException("stringBuilder"); } if (ArgumentEntity.ShowDateTime) { if (ArgumentEntity.HasDateTimeFormat) { stringBuilder.Append(DateTimeOffset.Now.ToString(ArgumentEntity.DateTimeFormat, CultureInfo.InvariantCulture)); } else { stringBuilder.Append(DateTimeOffset.Now); } stringBuilder.Append(" "); } if (ArgumentEntity.ShowLevel) { stringBuilder.Append(("[" + level.ToString().ToUpper() + "]").PadRight(8)); } if (ArgumentEntity.ShowLogName) { stringBuilder.Append(ArgumentEntity.LogName).Append(" - "); } stringBuilder.Append(message); if (e != null) { stringBuilder.Append(Environment.NewLine).Append(ExceptionFormatter.Format(e)); } }
public static string WriteLogEntry(List <object> curObjects, string logMessage, LogLevelType curLevel, Exception curException, string destinationMachineName) { LogLevel nLogLevel = LogLevel.FromString(curLevel.ToString()); LogObject curLogObject = new LogObject { Message = logMessage, CurrentDataObjects = curObjects }; Guid logGUID = Guid.NewGuid(); string uniqueID = logGUID.ToString(); string xmlMessage; using (StringWriter sw = new StringWriter()) { _curSerializer.Serialize(sw, curLogObject); xmlMessage = sw.ToString(); } LogEventInfo logRecord; if (curException != null) { logRecord = new LogEventInfo(nLogLevel, null, null, xmlMessage, null, curException); } else { logRecord = new LogEventInfo(nLogLevel, null, xmlMessage); } logRecord.Properties["DestinationMachineName"] = destinationMachineName; logRecord.Properties["UniqueID"] = uniqueID; _curLogger.Log(logRecord); return(uniqueID); }
public IEnumerable <ApplicationLog> RetrieveApplicationLogsByMessageType(LogLevelType type) { return(_iRavenApplicationLogEntities.ApplicationLogs.Where(p => p.MessageType == type.ToString())); }