public void Log(string toLogMessage, LogPriority priority, params object[] args) { if (LogRequested != null) { LogRequested(string.Format(toLogMessage, args), priority); } }
public LoggerArgs(LogPriority priority, string message, string priorityTitle = null) { Timestamp = DateTime.Now; Priority = priority; Message = message; if (priorityTitle != null) { PriorityTitle = priorityTitle; } else { switch (priority) { case LogPriority.Error: PriorityTitle = "ERROR"; break; case LogPriority.Warning: PriorityTitle = "warn"; break; case LogPriority.Info: PriorityTitle = "i"; break; } } LogString = Timestamp.ToString("yy-MM-dd HH:mm:ss.fff") + " [" + PriorityTitle + "] " + message; }
internal static string[] GetCategoryStringArray(LogPriority logPriority, LogCategory[] categories, bool addException) { if (categories == null) { categories = new LogCategory[] { }; } string[] categoryValues = (from category in categories select category.Value).ToArray(); string[] allCategories = null; if (addException) { allCategories = new string[categories.Length + 2]; allCategories[0] = logPriority.ToString(); allCategories[1] = LogCategory.Exception.ToString(); categoryValues.CopyTo(allCategories, 2); } else { allCategories = new string[categories.Length + 1]; allCategories[0] = logPriority.ToString(); categoryValues.CopyTo(allCategories, 1); } return allCategories; }
internal bool ShouldLog(TraceEventType severity, LogPriority priority, IEnumerable<LogCategory> categories) { return ShouldLog(severity, "All") || ShouldLog(severity, priority.ToString()) || categories.Any(c => ShouldLog(severity, c.ToString())); }
/// <summary> /// Shared method between constructors /// </summary> /// <param name="message"></param> /// <param name="priority"></param> /// <param name="destination"></param> /// <param name="encrypt"></param> private void Init(string message, LogPriority priority, ILogAppender destination, bool encrypt) { Message = encrypt ? Encryption.Encrypt(message) : message; Priority = priority; Destination = destination; _encrypt = encrypt; if (HttpContext.Current != null) _username = HttpContext.Current.User.Identity.Name; else if (WindowsIdentity.GetCurrent().Name != null) _username = WindowsIdentity.GetCurrent().Name; else _username = "******"; if (HttpContext.Current != null) _location = HttpContext.Current.Request.RawUrl; else if (!string.IsNullOrEmpty(Assembly.GetCallingAssembly().GetName().FullName)) _location = Assembly.GetCallingAssembly().GetName().FullName; else _location = "Unknown"; Date = DateTime.Now; }
// This is based on: // http://www.docjar.com/html/api/org/apache/log4j/Priority.java.html // http://www.docjar.com/html/api/org/apache/log4j/Level.java.html // private int GetLevel(LogPriority priority) { switch (priority) { case LogPriority.Fatal: return 50000; case LogPriority.Error: return 40000; case LogPriority.Warn: return 30000; case LogPriority.Info: return 20000; case LogPriority.Debug: return 10000; case LogPriority.Trace: return int.MinValue; } throw new NotSupportedException(string.Format("That priority level [{0}] is not supported", priority)); }
/// <summary> /// Writes a log entry via the logger from <see cref="Logger.Current" />. /// </summary> /// <param name="msg">The message to write.</param> /// <param name="category">The category.</param> /// <param name="prio">The priority.</param> /// <param name="tag">The optional tag.</param> /// <returns>Message was written or not.</returns> public static bool Log(object msg, LogCategory category = LogCategory.Info, LogPriority prio = LogPriority.None, string tag = null) { return Current.Log(msg: msg, category: category, prio: prio, tag: tag); }
public static void Log(LogPriority priority, string message, string priorityTitle = null) { var e = Logged; if (e != null) { e(new LoggerArgs(priority, message, priorityTitle)); } }
public static void Log(LogPriority priority, Exception exception, string message = null, string priorityTitle = null) { if (Logged == null) { return; } message = exception.Message + (message != null ? " (" + message + ")" : String.Empty) + ". Stack trace: \n" + exception.StackTrace; Log(priority, message, priorityTitle); }
public static void RecordLog(string title, LogEventType eventType, LogPriority priority, object extraObject, System.Exception e) { LogManager lm = new LogManager(); lm.Record(title, eventType, priority, extraObject, e); }
/// <summary> /// Writes a value as <see cref="LogCategory.Alert" /> message async. /// </summary> /// <param name="logger">The logger.</param> /// <param name="msg">The message value.</param> /// <param name="tag">The tag.</param> /// <param name="prio">The priority.</param> /// <returns>The running task.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="logger" /> is <see langword="null" />. /// </exception> public static Task<bool> AlertAsync(this ILogger logger, object msg, string tag = null, LogPriority prio = LogPriority.None) { return LogAsync(logger: logger, msg: msg, category: LogCategory.Alert, prio: prio, tag: tag); }
/// <summary> /// Async operation of <see cref="LoggerBase.Log(object, LogCategory, LogPriority, string)" /> method. /// </summary> /// <param name="msg">The message.</param> /// <param name="category">The category.</param> /// <param name="prio">The priority.</param> /// <param name="tag">The tag.</param> /// <returns>The started task.</returns> public Task<bool> LogAsync(object msg, LogCategory category = LogCategory.Info, LogPriority prio = LogPriority.None, string tag = null) { var logMsg = CreateMessage(msg: msg, category: category, prio: prio, tag: tag); return LogAsync(logMsg: logMsg); }
public void Log(string msg, LogPriority priority, LogCategory category) { string padding = "------"; Console.WriteLine(padding); Console.WriteLine(category.ToString()); Console.WriteLine(priority.ToString()); Console.WriteLine(msg); Console.WriteLine(padding); }
public LogEntry(string message, LogPriority priority, string[] tags = null) { this.Message = message; this.Priority = priority; this.Tags = tags; this.MethodName = "unknown"; this.SourceFilePath = "unknown"; this.LineNumber = 9999; this.LogException = null; this.currentStackTrace = "unknown"; }
public void Log(string message, LogCategory category, LogPriority priority) { Message = message; Category = category; Priority = priority; var trace = new StackTrace(); StackFrame frame = trace.GetFrame(1); MethodBase method = frame.GetMethod(); Logger.Log(LogLevel.Info, method.DeclaringType + ": " + message); _aggregator.GetEvent<LogEvent>().Publish(new NLogService { Message = Message, Category = Category, Priority = Priority }); }
internal void Write( Exception exception, string title, string message, TraceEventType severity, LogPriority logPriority, IDictionary<string, object> extendedProperties, params LogCategory[] categories) { try { if (!this.loggingEnabled || !this.logWriter.IsLoggingEnabled()) { return; } bool isException = exception != null; LogEntry logEntry = new LogEntry() { Title = title ?? string.Empty, Message = message, Severity = severity, Priority = (int)logPriority, ExtendedProperties = extendedProperties, Categories = GetCategoryStringArray(logPriority, categories, isException) }; if (!ShouldLog(logEntry.Severity, logPriority, logEntry.Categories)) { return; } logEntry.ExtendedProperties.Add("Source", sourceName); new ManagedSecurityContextInformationProvider().PopulateDictionary(logEntry.ExtendedProperties); new HttpContextInformationProvider().PopulateDictionary(logEntry.ExtendedProperties); if (isException) { AddExceptionInfoToLogEntry(exception, logEntry); } logWriter.Write(logEntry); } catch (Exception ex) { LogErrorDirectlyInEventLog(ex.ToString()); } }
public static void ReportLog(object val, LogPriority priority = LogPriority.Low) { try { var text = val.ToString(); if (priority != LogPriority.Low) EventLog.WriteEntry(Const.EventLogSourceName, text); WebLogger.Report(val); } catch (Exception exc) { Trace.WriteLine(val); Trace.WriteLine(exc); } }
/// <summary> /// Writes a message to the log. /// </summary> /// <param name="message">The message to write.</param> /// <param name="category">The message category.</param> /// <param name="priority">The log priority.</param> public void Log(string message, LogCategory category, LogPriority priority) { switch (category) { case LogCategory.Debug: logger.Debug(message); break; case LogCategory.Warn: logger.Warn(message); break; case LogCategory.Exception: logger.Error(message); break; case LogCategory.Info: logger.Info(message); break; } }
private void eventLogger_LogRequested(string toLog, LogPriority priority) { switch (priority) { case LogPriority.NORMAL: Console.ForegroundColor = _defaultColor; Console.WriteLine(toLog); break; case LogPriority.ERROR: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(toLog); break; case LogPriority.WARNING: Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(toLog); break; } }
private static Priority GetPriority(LogPriority priority) { switch (priority) { case LogPriority.Debug: return Priority.DEBUG; case LogPriority.Error: return Priority.ERROR; case LogPriority.Fatal: return Priority.FATAL; case LogPriority.Info: return Priority.INFO; case LogPriority.Trace: return Priority.TRACE; case LogPriority.Warn: return Priority.WARN; } throw new NotSupportedException(string.Format("That priority level [{0}] is not supported", priority)); }
/// <summary> /// Writes a value as <see cref="LogCategory.Alert" /> message. /// </summary> /// <param name="logger">The logger.</param> /// <param name="msg">The message value.</param> /// <param name="tag">The tag.</param> /// <param name="prio">The priority.</param> /// <returns>Operation was successful or not.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="logger" /> is <see langword="null" />. /// </exception> public static bool Alert(this ILogger logger, object msg, string tag = null, LogPriority prio = LogPriority.None) { if (logger == null) { throw new ArgumentNullException("logger"); } try { return logger.Log(msg: msg, category: LogCategory.Alert, prio: prio, tag: tag); } catch { return false; } }
/// <summary> /// 记录流程异常日志 /// </summary> /// <param name="entity"></param> public void Record(string title, LogEventType eventType, LogPriority priority, object extraObject, System.Exception e) { try { var log = new LogEntity(); log.EventTypeID = (int)eventType; log.Priority = (int)priority; log.Severity = priority.ToString().ToUpper(); log.Title = title; log.Timestamp = DateTime.Now; log.Message = e.Message; log.StackTrace = e.StackTrace.Length > 4000 ? e.StackTrace.Substring(0, 4000): e.StackTrace; if (e.InnerException != null) { log.InnerStackTrace = e.InnerException.StackTrace.Length > 4000 ? e.InnerException.StackTrace.Substring(0, 4000) : e.InnerException.StackTrace; } if (extraObject != null) { var jsonData = JsonSerializer.SerializeToString(extraObject); log.RequestData = jsonData.Length > 2000 ? jsonData.Substring(0, 2000) : jsonData; } //线程池添加日志记录 ThreadPool.QueueUserWorkItem(new WaitCallback(Insert), log); } catch { //如果记录日志发生异常,不做处理 ; } }
public static Task PostDataAsync(object?obj, string?tag = null, bool copyToDebug = false, LogPriority priority = LogPriority.Info, CancellationToken cancel = default, bool noWait = false) { Post(obj, priority, kind: LogKind.Data, tag: tag); if (copyToDebug) { Post(new PostedData() { Data = obj, Tag = tag }, priority: LogPriority.Debug, kind: LogKind.Default, tag: tag); } // データを post したときは一定個数ごとに Half Flush し、Half Flush 完了まで待機をする (消失防止のため) if (noWait == false && (PostDataFlushCountPer == 0 || (Interlocked.Increment(ref PostDataCounter) % PostDataFlushCountPer) == 0)) { return(FlushAsync(halfFlush: true, cancel: cancel)); } else { return(Task.CompletedTask); } }
private bool ShouldLog(TraceEventType severity, LogPriority priority, IEnumerable<string> categories) { return ShouldLog(severity, priority.ToString()) || categories.Any(c => ShouldLog(severity, c)); }
public Entry(string msg, LogPriority priority) { m_msg = msg; m_time = DateTime.Now; m_priority = priority; }
public static void PostData(object?obj, string?tag = null, bool copyToDebug = false, LogPriority priority = LogPriority.Info, CancellationToken cancel = default, bool noWait = false) => PostDataAsync(obj, tag, copyToDebug, priority, cancel, noWait)._GetResult();
public static void Log(string msg, LogPriority priority, LogCategory category) { if (Logger != null) Logger.Log(msg, priority, category); }
/// <summary> /// 重载的构造函数 /// </summary> /// <param name="name">名称</param> /// <param name="minPriority">优先级阀值</param> /// <remarks> /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\\Logging\LogFilterPipelineTest.cs" /// lang="cs" region="ILogFilter AddRemove Test" tittle="增删LogFillter对象"></code> /// </remarks> public PriorityLogFilter(string name, LogPriority minPriority) : base(name) { this.minPriority = minPriority; }
public static void Post(object?obj, LogPriority priority = LogPriority.Debug, string kind = LogKind.Default, LogFlags flags = LogFlags.None, string?tag = null) => Router?.PostLog(new LogRecord(obj, priority, flags, tag), kind);
public void LogException(LogPriority priority, string source, Exception e) { }
public void Log(LogPriority priority, string format, params object[] args) { }
public void Log(LogPriority priority, string message) { }
internal static extern int Print(LogPriority prio, string tag, string fmt, string file, string func, int line, string msg);
internal static extern int Print(LogPriority prio, string tag, string fmt, string msg);
/// <summary> /// 重载的构造函数,从配置文件中读取、构造 /// </summary> /// <param name="element">配置对象</param> /// <remarks> /// <code source="..\Framework\src\DeluxeWorks.Library\Logging\Filters\LogFilterFactory.cs" /// lang="cs" region="Get FilterPipeline" title="获取Filter对象"></code> /// </remarks> public PriorityLogFilter(LoggerFilterConfigurationElement element) : base(element.Name) { this.minPriority = element.MinPriority; }
public void FlushToLog(LogPriority logPriority, params LogCategory[] categories) { this.FlushToLog(string.Empty, logPriority, categories); }
private LogPriority GetMaximumPriority(LogPriority logPriority) { return this.LogPriority.HasValue ? (LogPriority)Math.Max((int)this.LogPriority.Value, (int)logPriority) : logPriority; }
public CatPrior(LogCategory category, LogPriority priority) : this() { Category = category; Priority = priority; }
public LogEntry(LogPriority priority) : this("", LogCategory.Info, priority) { }
/// <summary> /// 记录日志到数据库 /// </summary> /// <param name="logTitle">日志标题</param> /// <param name="logMsg">日志内容</param> /// <param name="userName">用户名</param> /// <param name="logCategory">日志类别</param> /// <param name="logPriority">日志等级</param> /// <param name="logSource">异常信息</param> public void SaveLog(string logTitle, string logMsg, string userName = "", LogCategory logCategory = LogCategory.SystemAction, LogPriority logPriority = LogPriority.Normal, string logSource = "") { _repository.SaveLog(logTitle, logMsg, userName, logCategory, logPriority, logSource); }
public static void PostSocketLog(object?obj, string?tag = null, bool copyToDebug = false, LogPriority priority = LogPriority.Info) { Post(obj, priority, kind: LogKind.Socket, tag: tag); if (copyToDebug) { Post(new PostedSocketLog() { Data = obj, Tag = tag }, priority: LogPriority.Debug, kind: LogKind.Default, tag: tag); } }
public LogEntry(LogCategory level, LogPriority priority) : this("", level, priority) { }
public static extern void SDL_LogSetAllPriority(LogPriority level);
public SmtpLogRoute(string kind, LogPriority minimalPriority, SmtpLogRouteSettings settings) : base(kind, minimalPriority) { this.Settings = settings; }
public void Log(string message, LogPriority p) { m_mutex.WaitOne(); m_tsEntriesI.Enqueue(new Entry(message, p)); m_mutex.ReleaseMutex(); }
public ConsoleLogRoute(string kind, LogPriority minimalPriority) : base(kind, minimalPriority) { }
public static extern void SDL_LogMessage( LogCategory category, LogPriority priority, /*const char*/ byte *fmt //__arglist );
public void LogException(LogPriority priority, string source, Exception e) { Log(LogPriority.Error, $"!!! Received exception from \"{ source }\":"); App.LogException(this, e); }
public static extern void SDL_LogSetPriority(LogCategory category, LogPriority level);
internal static bool IsLowerPriorityThan(this LogPriority @this, LogPriority other) { return((int)@this > (int)other); }
public static void PrintConsole(object?obj, bool noConsole = false, LogPriority priority = LogPriority.Info, string?tag = null, LogFlags flags = LogFlags.None) => Post(obj, priority, flags: flags | (noConsole ? LogFlags.NoOutputToConsole : LogFlags.None), tag: tag);
/// <summary> /// Initialises a new instance of the <see cref="EnterpriseLogger"/> class with the given list of categories, priority and event id. /// </summary> /// <param name="categories">The list of categories related to the message.</param> /// <param name="priority">The priority of the message.</param> /// <param name="eventId">The event id of the message. Specially applicable for messages being logged to the Windows Event Log.</param> public EnterpriseLogger(IEnumerable <string> categories, LogPriority priority, int eventId) : base(categories, priority, eventId) { _writer = _logWriterFactory.Create(); }
public void FlushToLog(string title, LogPriority logPriority, params LogCategory[] categories) { if (!this.entries.Any()) { return; } try { var severity = this.GetMaximumSeverity(); logPriority = this.GetMaximumPriority(logPriority); if (Log.ShouldLog(severity, logPriority, categories) || this.entries.All(entry => entry.Exception == null)) { Log.Write( title, this.GetMessage(), severity, logPriority, null, categories); } } finally { this.entries.Clear(); } }
/// <summary> /// Initialises a new instance of the <see cref="EnterpriseLogger"/> class with the given list of categories, priority, event id, severity and title. /// </summary> /// <param name="categories">The list of categories related to the message.</param> /// <param name="priority">The priority of the message.</param> /// <param name="eventId">The event id of the message. Specially applicable for messages being logged to the Windows Event Log.</param> /// <param name="severity">The severity of the message.</param> /// <param name="title">The title of the message.</param> public EnterpriseLogger(IEnumerable <string> categories, LogPriority priority, int eventId, TraceEventType severity, string title) : base(categories, priority, eventId, severity, title) { _writer = _logWriterFactory.Create(); }
/// <summary> /// Initializes a new instance of the <see cref="LogEntry"/> class. /// </summary> /// <param name="message">The message.</param> /// <param name="priority">The priority.</param> /// <param name="destination">The destination.</param> /// <param name="encrypt">if set to <c>true</c> [encrypt].</param> public LogEntry(string message, LogPriority priority, ILogAppender destination, bool encrypt) { Init(message, priority, destination, encrypt); }
/// <summary> /// Writes a message to a log with the given list of categories, priority, event id and severity. /// </summary> /// <remarks> /// Only writes to the log if logging is enabled, which can be verified through <see cref="IsLoggingEnabled"/>. /// </remarks> /// <param name="message">The message to be written to the log.</param> /// <param name="categories">The category related to the message.</param> /// <param name="priority">The priority of the message.</param> /// <param name="eventId">The event id of the message. Specially applicable for messages being logged to the Windows Event Log.</param> /// <param name="severity">The severity of the message.</param> public void Write(string message, IEnumerable <string> categories, LogPriority priority, int eventId, System.Diagnostics.TraceEventType severity) { Write(message, categories, priority, eventId, severity, this.Title); }
public LogRouteBase(string kind, LogPriority minimalPriority) { this.MinimalPriority = minimalPriority; SetKind(kind); }
/// <summary> /// Writes a message to a log with the given list of categories and priority. /// </summary> /// <remarks> /// Only writes to the log if logging is enabled, which can be verified through <see cref="IsLoggingEnabled"/>. /// </remarks> /// <param name="message">The message to be written to the log.</param> /// <param name="categories">A list of categories related to the message.</param> /// <param name="priority">The priority of the message.</param> /// <param name="userId">The user id of the user responsible for the message.</param> public void Write(string message, IEnumerable <string> categories, LogPriority priority, int userId) { Write(message, categories, priority, this.EventId, this.Severity, this.Title, userId); }
public void Write(LogCategory category, LogPriority priority, Boolean system, String message, params Object[] args) { Source.Write(category, priority, system, ScopePrefix + message, args); }
public Log() { this.logId = System.Threading.Interlocked.Increment(ref counter); this.Priority = LogPriority.Info; }