private void ProccessCommand(ReportLevels reportLevel, string date, string message) { switch (reportLevel) { case ReportLevels.Info: this.logger.Info(date, message); break; case ReportLevels.Critical: this.logger.Critical(date, message); break; case ReportLevels.Fatal: this.logger.Fatal(date, message); break; case ReportLevels.Warning: this.logger.Warning(date, message); break; case ReportLevels.Error: this.logger.Error(date, message); break; } }
public void Run() { int n = int.Parse(this.reader.ReadLine()); IAppender[] appenders = this.ReadAppenders(n); this.logger = new Loogger(appenders); while (true) { string line = this.reader.ReadLine(); if (line == "END") { break; } string[] parts = line.Split('|'); ReportLevels reportLevel = Enum.Parse <ReportLevels>(parts[0], true); string date = parts[1]; string message = parts[2]; this.ProccessCommand(reportLevel, date, message); } Console.WriteLine(logger); }
/// <summary> /// Checks the integrity of an NTFS file system held in a stream. /// </summary> /// <param name="reportOutput">A report on issues found</param> /// <param name="levels">The amount of detail to report</param> /// <returns><c>true</c> if the file system appears valid, else <c>false</c></returns> public override bool Check(TextWriter reportOutput, ReportLevels levels) { _context = new NtfsContext(); _context.RawStream = _target; _context.Options = new NtfsOptions(); _report = reportOutput; _reportLevels = levels; _levelsDetected = ReportLevels.None; try { DoCheck(); } catch (AbortException ae) { ReportError("File system check aborted: " + ae.ToString()); return(false); } catch (Exception e) { ReportError("File system check aborted with exception: " + e.ToString()); return(false); } return((_levelsDetected & _levelsConsideredFail) == 0); }
public virtual void Append(string dateTimeInfo, ReportLevels reportLevel, string message) { if (reportLevel >= this.ReportLevel) { this.Append(dateTimeInfo, reportLevel.ToString(), message); } }
public IAppender CreateAppender(string type, ILayout layout, ReportLevels reportLevel) { IAppender appender; switch (type) { case nameof(ConsoleAppender): appender = new ConsoleAppender(layout) { ReportLevel = reportLevel }; break; case nameof(FileAppender): appender = new FileAppender(layout, new LogFile()) { ReportLevel = reportLevel }; break; default: throw new ArgumentException($"{type} is invalid appender type"); } return(appender); }
/// <summary> /// This method is the interception where the module can interact with the execution environment and modify the settings. /// </summary> /// <param name="commandlineOptions">A set of commandline options passed to Duplicati</param> public void Configure(IDictionary<string, string> commandlineOptions) { //We need at least a recipient commandlineOptions.TryGetValue(OPTION_RECIPIENT, out m_to); if (string.IsNullOrEmpty(m_to)) return; commandlineOptions.TryGetValue(OPTION_USERNAME, out m_username); commandlineOptions.TryGetValue(OPTION_PASSWORD, out m_password); commandlineOptions.TryGetValue(OPTION_MESSAGE, out m_body); m_options = commandlineOptions; m_level = 0; string tmp; commandlineOptions.TryGetValue(OPTION_SENDLEVEL, out tmp); if (!string.IsNullOrEmpty(tmp)) foreach(var s in tmp.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries)) { if (string.IsNullOrEmpty(s)) continue; ReportLevels m; if (Enum.TryParse(s.Trim(), true, out m)) m_level |= m; } if (m_level == 0) m_level = DEFAULT_LEVEL; m_sendAll = Utility.Utility.ParseBoolOption(commandlineOptions, OPTION_SENDALL); if (string.IsNullOrEmpty(m_body)) m_body = DEFAULT_MESSAGE; }
private void AppendToAppenders(string date, ReportLevels reportLevel, string message) { foreach (var appender in this.appenders) { appender.Append(date, reportLevel, message); } }
/// <summary> /// Checks the integrity of an NTFS file system held in a stream. /// </summary> /// <param name="reportOutput">A report on issues found.</param> /// <param name="levels">The amount of detail to report.</param> /// <returns><c>true</c> if the file system appears valid, else <c>false</c>.</returns> public override bool Check(TextWriter reportOutput, ReportLevels levels) { _context = new NtfsContext(); _context.RawStream = _target; _context.Options = new NtfsOptions(); _report = reportOutput; _reportLevels = levels; _levelsDetected = ReportLevels.None; try { DoCheck(); } catch (AbortException ae) { ReportError("File system check aborted: " + ae.ToString()); return false; } catch (Exception e) { ReportError("File system check aborted with exception: " + e.ToString()); return false; } return (_levelsDetected & _levelsConsideredFail) == 0; }
private void ReportDump(IDiagnosticTraceable toDump) { _levelsDetected |= ReportLevels.Information; if ((_reportLevels & ReportLevels.Information) != 0) { toDump.Dump(_report, "INFO: "); } }
private void ReportInfo(string str, params object[] args) { _levelsDetected |= ReportLevels.Information; if ((_reportLevels & ReportLevels.Information) != 0) { _report.WriteLine("INFO: " + str, args); } }
private void ReportWarning(string str, params object[] args) { _levelsDetected |= ReportLevels.Warnings; if ((_reportLevels & ReportLevels.Warnings) != 0) { _report.WriteLine("WARNING: " + str, args); } }
private void ReportError(string str, params object[] args) { _levelsDetected |= ReportLevels.Errors; if ((_reportLevels & ReportLevels.Errors) != 0) { _report.WriteLine("ERROR: " + str, args); } }
private void Log(string log, ReportLevels report) { var dateTime = DateTime.Now; foreach (var appender in Appenders) { appender.Append(log, report, dateTime); } }
public override void Append(string date, ReportLevels reportLevel, string message) { if (this.CanAppend(reportLevel)) { string content = string.Format(this.layout.Template, date, reportLevel, message) + Environment.NewLine; this.logFile.Write(content); this.MessagesCount++; } }
private IAppender[] ReadAppenders(int n) { IAppender[] appenders = new IAppender[n]; for (int i = 0; i < n; i++) { string[] appenderParts = this.reader.ReadLine().Split(); string appenderType = appenderParts[0]; string layoutType = appenderParts[1]; ReportLevels reportLevel = appenderParts.Length == 3 ? Enum.Parse <ReportLevels>(appenderParts[2], true) : ReportLevels.Info; ILayout layout = this.layoutFactory.CreateLayout(layoutType); IAppender appender = this.appenderFactory.CreateAppender(appenderType, layout, reportLevel); appenders[i] = appender; } return(appenders); }
/// <summary> /// Verifies the VHD file, generating a report and a pass/fail indication. /// </summary> /// <param name="reportOutput">The destination for the report</param> /// <param name="levels">How verbose the report should be</param> /// <returns><c>true</c> if the file is valid, else false</returns> public bool Check(TextWriter reportOutput, ReportLevels levels) { _report = reportOutput; _reportLevels = levels; _levelsDetected = ReportLevels.None; try { DoCheck(); } catch (AbortException ae) { ReportError("File system check aborted: " + ae.ToString()); return(false); } catch (Exception e) { ReportError("File system check aborted with exception: " + e.ToString()); return(false); } return((_levelsDetected & _levelsConsideredFail) == 0); }
/// <summary> /// Verifies the VHD file, generating a report and a pass/fail indication. /// </summary> /// <param name="reportOutput">The destination for the report.</param> /// <param name="levels">How verbose the report should be.</param> /// <returns><c>true</c> if the file is valid, else false.</returns> public bool Check(TextWriter reportOutput, ReportLevels levels) { _report = reportOutput; _reportLevels = levels; _levelsDetected = ReportLevels.None; try { DoCheck(); } catch (AbortException ae) { ReportError("File system check aborted: " + ae.ToString()); return false; } catch (Exception e) { ReportError("File system check aborted with exception: " + e.ToString()); return false; } return (_levelsDetected & _levelsConsideredFail) == 0; }
private void ReportDump(IDiagnosticTraceable toDump) { _levelsDetected |= ReportLevels.Information; if ((_reportLevels & ReportLevels.Information) != 0) { toDump.Dump(_report, "INFO: "); } }
public abstract void Append(string msg, ReportLevels report, DateTime dateTime);
/// <summary> /// Checks the integrity of a file system held in a stream. /// </summary> /// <param name="reportOutput">A report on issues found</param> /// <param name="levels">The amount of detail to report</param> /// <returns><c>true</c> if the file system appears valid, else <c>false</c></returns> public abstract bool Check(TextWriter reportOutput, ReportLevels levels);
public override void Append(string msg, ReportLevels report, DateTime dateTime) { string tempMsg = this.Layout.Format(report, msg, dateTime); Console.WriteLine(tempMsg); }
public Appender(string layoutType, string reportLevel) { reportLevel = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(reportLevel.ToLower()); ReportLevel = (ReportLevels)Enum.Parse(typeof(ReportLevels), reportLevel); this.Layout = GetLayout(layoutType); }
public abstract void Append(string date, ReportLevels reportLevel, string message);
protected bool CanAppend(ReportLevels reportLevel) { return(reportLevel >= this.ReportLevel); }
/// <summary> /// This method is the interception where the module can interact with the execution environment and modify the settings. /// </summary> /// <param name="commandlineOptions">A set of commandline options passed to Duplicati</param> public void Configure(IDictionary<string, string> commandlineOptions) { //We need at least a recipient commandlineOptions.TryGetValue(OPTION_RECIPIENT, out m_to); if (string.IsNullOrEmpty(m_to)) return; commandlineOptions.TryGetValue(OPTION_USERNAME, out m_username); commandlineOptions.TryGetValue(OPTION_PASSWORD, out m_password); commandlineOptions.TryGetValue(OPTION_MESSAGE, out m_body); m_options = commandlineOptions; m_level = 0; string tmp; commandlineOptions.TryGetValue(OPTION_SENDLEVEL, out tmp); if (!string.IsNullOrEmpty(tmp)) foreach(var s in tmp.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries)) { if (string.IsNullOrEmpty(s)) continue; ReportLevels m; if (Enum.TryParse(s.Trim(), true, out m)) m_level |= m; } if (m_level == 0) m_level = DEFAULT_LEVEL; m_sendAll = Utility.Utility.ParseBoolOption(commandlineOptions, OPTION_SENDALL); if (string.IsNullOrEmpty(m_body)) m_body = DEFAULT_MESSAGE; }
private void ReportWarning(string str, params object[] args) { _levelsDetected |= ReportLevels.Warnings; if ((_reportLevels & ReportLevels.Warnings) != 0) { _report.WriteLine("WARNING: " + str, args); } }
private void ReportInfo(string str, params object[] args) { _levelsDetected |= ReportLevels.Information; if ((_reportLevels & ReportLevels.Information) != 0) { _report.WriteLine("INFO: " + str, args); } }
private void ReportError(string str, params object[] args) { _levelsDetected |= ReportLevels.Errors; if ((_reportLevels & ReportLevels.Errors) != 0) { _report.WriteLine("ERROR: " + str, args); } }
/// <summary> /// Checks the integrity of a file system held in a stream. /// </summary> /// <param name="reportOutput">A report on issues found</param> /// <param name="levels">The amount of detail to report</param> /// <returns><c>true</c> if the file system appears valid, else <c>false</c></returns> public abstract bool Check(TextWriter reportOutput, ReportLevels levels);
public override string Format(ReportLevels report, string levels, DateTime dateTime) { return string.Format(FormatType, dateTime, report, levels); }
public abstract string Format(ReportLevels report, string levels, DateTime dateTime);