/// <summary> /// Formats the message. /// </summary> /// <param name="log"></param> /// <param name="buf"></param> /// <returns></returns> public string Format(ILog log, LogLevel level, LogArgs args) { StringBuilder builder = new StringBuilder(); AppendDateTime(builder); builder.Append(InterpunctSep); AppendLevelName(builder, level); builder.Append(InterpunctSep); AppendThreadName(builder); builder.Append(InterpunctSep); builder.Append(log.Name); builder.Append(" "); while (builder.Length % 4 != 0) { builder.Append(" "); } builder.Append(args.Message); // ex? if (args.HasException) { builder.Append("\r\n\t"); builder.Append(args.Exception); } // return... return(builder.ToString()); }
public string Format(ILog log, BootFX.Common.Management.LogLevel level, LogArgs args) { // mbr - 22-05-2008 - changed this to add date/time, because that's always handy. // // mbr - 20-08-2006 - wasn't handling exceptions... // if(ex == null) // return buf; // else // return string.Format("{0}\r\n\t{1}", buf, ex); // builder... StringBuilder builder = new StringBuilder(); DefaultLogFormatter.AppendDateTime(builder); builder.Append(" | "); builder.Append(args.Message); // ex? if (args.HasException) { builder.Append("\r\n\t"); builder.Append(args.Exception); } // return... return(builder.ToString()); }
/// <summary> /// Logs the given message. /// </summary> /// <param name="level"></param> /// <param name="buf"></param> /// <returns></returns> internal void LogMessage(LogLevel level, string buf, Exception exception = null, Action <LogArgs> options = null) { var args = new LogArgs(buf, exception); if (options != null) { options(args); } this.LogMessage(level, args); }
public string Format(ILog log, BootFX.Common.Management.LogLevel level, LogArgs args) { if (args.HasException) { return(string.Format("{0}\r\n\r\nException:\r\n{1}", args.Message, args.Exception)); } else { return(args.Message + "\r\n\r\n(No exception)"); } }
/// <summary> /// Constructor. /// </summary> /// <param name="level"></param> /// <param name="unformattedBuf"></param> /// <param name="exception"></param> /// <param name="formattedBuf"></param> public LogData(LogLevel level, LogArgs args, string formattedBuf) { _level = level; _unformattedBuf = args.Message; _exception = args.Exception; this.System = args.System; this.Category = args.Category; _formattedBuf = formattedBuf; this.Color = args.Color; this.HasColor = args.HasColor; // mbr - 07-11-2005 - other stuff... _dateTime = DateTime.UtcNow; //_entryAssembly = Assembly.GetEntryAssembly(); // mbr - 08-02-2008 - changed to use low-trust and shared thread method... if (Runtime.IsStarted && !(Runtime.Current.IsLowTrust)) { _threadId = Runtime.GetCurrentThreadId(); } else { _threadId = 0; } // set... _isThreadPoolThread = Thread.CurrentThread.IsThreadPoolThread; _threadName = GetThreadName(); //// user... //IPrincipal principal = Thread.CurrentPrincipal; //if(principal != null && principal.Identity != null && principal.Identity.IsAuthenticated) // _windowsUsername = principal.Identity.Name; //// mbr - 07-11-2005 - http... //HttpContext context = HttpContext.Current; //if(context != null && context.Request != null) //{ // _isHttpRequest = true; // _httpUrl = context.Request.Url.LocalPath; // _httpQueryString = context.Request.Url.Query; //} }
private void LogMessage(LogLevel level, LogArgs args) { if (this.IsLevelEnabled(level) == false) { return; } // walk the appenders... foreach (Appender appender in this.Appenders) { try { appender.Append(level, args); } catch (Exception ex) { LogManager.InternalError(string.Format("Failed to append to '{0}'.", appender), ex); } } }
/// <summary> /// Appends a message. /// </summary> /// <param name="buf"></param> public void Append(LogLevel level, LogArgs args) { if (Log == null) { throw new InvalidOperationException("Log is null."); } if (Formatter == null) { throw new InvalidOperationException("Formatter is null."); } // are we supported for this level? if (this.IsLevelEnabled(level)) { // format it... string formatted = this.Formatter.Format(this.Log, level, args); // package it... LogData data = new LogData(level, args, formatted); // mbr - 07-11-2005 - if the appender supports lazy writing, do it in a background thread... //if(this.LazyWrite && Runtime.IsStarted) //{ // // do we have the service? // if(Runtime.Current.InternalManagementService == null) // throw new InvalidOperationException("Runtime.Current.InternalManagementService is null."); // if(Runtime.Current.InternalManagementService.LazyLoggingEngine == null) // throw new InvalidOperationException("Runtime.Current.InternalManagementService.LazyLoggingEngine is null."); // // queue it... // Runtime.Current.InternalManagementService.LazyLoggingEngine.Enqueue((Appender)this, data); //} //else { // write it... this.DoAppend(data); } } }
public string Format(ILog log, BootFX.Common.Management.LogLevel level, LogArgs args) { StringBuilder builder = new StringBuilder(); DefaultLogFormatter.AppendDateTime(builder); builder.Append(" | "); DefaultLogFormatter.AppendLevelName(builder, level); builder.Append(" | "); DefaultLogFormatter.AppendThreadName(builder); builder.Append(" | "); builder.Append(args.Message); // ex? if (args.HasException) { builder.Append("\r\n\t"); builder.Append(args.Exception); } // return... return(builder.ToString()); }
public void Trace(LogArgs args) { this.LogMessage(LogLevel.Trace, args); }
public void Trace(LogArgs args) { }
public void Fatal(LogArgs args) { // TODO: Add NullLog.Fatal implementation }
public void Error(LogArgs args) { // TODO: Add NullLog.Error implementation }
public void Warn(LogArgs args) { // TODO: Add NullLog.Warn implementation }
public void Info(LogArgs args) { // TODO: Add NullLog.Info implementation }
public void Debug(LogArgs args) { // TODO: Add NullLog.Debug implementation }
public void Debug(LogArgs args) { this.LogMessage(LogLevel.Debug, args); }
public void Info(LogArgs args) { this.LogMessage(LogLevel.Info, args); }
public void Fatal(LogArgs args) { this.LogMessage(LogLevel.Fatal, args); }
public void Error(LogArgs args) { this.LogMessage(LogLevel.Error, args); }
public void Warn(LogArgs args) { this.LogMessage(LogLevel.Warn, args); }