public void AddLog(LogType type, string log, string condition, string stackTrace) { int logHash = log.GetHashCode(); if (TypeCount.ContainsKey(type)) { TypeCount[type]++; } else { TypeCount[type] = 1; } if (!CachedLogs.TryGetValue(logHash, out LogCounter cache)) { cache = new LogCounter(logHash, type, log); CachedLogs[logHash] = cache; elasticSearchDelivery.SendLog(type, condition, stackTrace); } else { cache.Increment(); } }
public void SendMail() { QueueTest queueTest = new QueueTest(); queueTest.BuildQueue(); ILog log = new LogCounter(); SendMailProcess sendMailProcess = new SendMailProcess(log); sendMailProcess.SetHostAndPort("smtp.hostname.com", 25); QueueProcess queueProcess = new QueueProcess(); Queue queue = queueProcess.GetQueue(); foreach (Recipient recipient in queue.RecipientData) { sendMailProcess.Send( new MailAddress(queue.TicketData.SenderAddress, queue.TicketData.SenderName), new MailAddress[] { new MailAddress(recipient.Address, recipient.Name) }, queue.TicketData.Subject, queue.TicketData.Body ); } }
public static void Main(string[] args) { PrintAbout(); bool pauseOnExit = true; var consoleLogger = new FilteredLogger(new ConsoleLogger()); var counter = new LogCounter(); var loggers = new LoggerCollection { consoleLogger, counter }; FileOutputLogger fileLogger = null; var parser = new CommandLineParser(); foreach (var @switch in CommandLineSwitches.AllSwitches) { parser.AddSwitch(@switch); } try { var result = parser.Parse(args); if (result.Flags.Contains(CommandLineSwitches.EnableTroublenoobing)) { throw new DevirtualisationException("Magikarp uses Splash! It was not very effective..."); } pauseOnExit = !result.Flags.Contains(CommandLineSwitches.NoPause); if (result.Flags.Contains(CommandLineSwitches.Help)) { PrintHelp(); } else { consoleLogger.IncludeDebug = result.Flags.Contains(CommandLineSwitches.VerboseOutput) || result.Flags.Contains(CommandLineSwitches.VeryVerboseOutput); consoleLogger.IncludeDebug2 = result.Flags.Contains(CommandLineSwitches.VeryVerboseOutput); var options = GetDevirtualisationOptions(result); options.OutputOptions.EnsureDirectoriesExist(); if (result.Flags.Contains(CommandLineSwitches.OutputLogFile)) { fileLogger = new FileOutputLogger(Path.Combine(options.OutputOptions.RootDirectory, "report.log")); loggers.Add(fileLogger); } if (result.Flags.Contains(CommandLineSwitches.SalvageData)) { loggers.Warning(Tag, "Salvage mode is enabled. Output files might not be an accurate representation of the original binary."); } var devirtualiser = new Devirtualiser(loggers); devirtualiser.Devirtualise(options); } } catch (CommandLineParseException ex) { consoleLogger.Error(Tag, ex.Message); consoleLogger.Log(Tag, "Use -h for help."); } catch (Exception ex) when(!Debugger.IsAttached) { consoleLogger.Error(Tag, "Something went wrong! Try the latest version or report a bug at the repository."); if (consoleLogger.IncludeDebug) { loggers.Error(Tag, ex.ToString()); } else { PrintExceptions(new LoggerCollection { consoleLogger, counter }, new[] { ex }); fileLogger?.Error(Tag, ex.ToString()); consoleLogger.Error(Tag, "Use --verbose or inspect the full report.log using --log-file for more details."); } } finally { loggers.Log(Tag, $"Process finished with {counter.Warnings} warnings and {counter.Errors} errors."); fileLogger?.Dispose(); } if (pauseOnExit) { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }
public void Process() { if (processing || this.smtpServer == null) { return; } lock (lockObj) { processing = true; } QueueProcess queueProcess = new QueueProcess(); int blockSleep = Convert.ToInt32(ConfigurationManager.AppSettings["BlockSleep"]); ClickOnceDMLib.Structs.Queue queue = queueProcess.GetQueue(); if (queue != null) { InitSMTPServer(); LogProcess.Info("In-Process Start"); ILog log = new LogCounter(); // log interface foreach (Recipient recipient in queue.RecipientData) { long baseTick = DateTime.Now.Ticks; var smtp = from s1 in this.smtpServer orderby s1.Weight ascending select s1; SMTPServer serverInfo = smtp.First(); SendMailProcess sendMailProcess = new SendMailProcess(log); sendMailProcess.SetHostAndPort(serverInfo.Host, serverInfo.Port); MailAddress mailAddress = null; try { mailAddress = new MailAddress(recipient.Address.Trim(), recipient.Name); } catch (Exception ex) { LogProcess.Error(ex); continue; } if (mailAddress != null) { sendMailProcess.Send( new MailAddress(queue.TicketData.SenderAddress, queue.TicketData.SenderName), new MailAddress[] { mailAddress }, queue.TicketData.Subject, queue.TicketData.Body ); serverInfo.SetWeight(TimeSpan.FromTicks(DateTime.Now.Ticks - baseTick).Milliseconds); } } log.Flush(); // write log LogProcess.Info("In-Process End"); Thread.Sleep(blockSleep); } processing = false; }
public void WriteEntry(Exception ex, int errorCode) { string message; string logKey = this.MakeLogKey(ex, errorCode); LogCounter counter = this.GetLogCounter(logKey); bool needRefresh = false; bool needWriteLog = true; lock (this.LogCounterList) { counter = this.GetLogCounter(logKey); if (counter == null) { counter = new LogCounter(); this.LogCounterList.Add(logKey, counter); } else { needRefresh = counter.NeedRefresh(); needWriteLog = counter.NeedWriteLog(); if (needRefresh) { counter.Refresh(); } else { counter.Increase(); } } } if (needWriteLog) { message = this.TruncateForEventLog(ex.ToString()); this.BaseWriteEntry(message, EventLogEntryType.Error, errorCode); } else if (needRefresh) { message = string.Format("{0} of {1} skipped.", counter.SkippedCounter, logKey); this.BaseWriteEntry(message, EventLogEntryType.Information, 0); } if (IsTraced) { Tracer.Instance.Write(TraceClass, "WriteEntry", ex, errorCode); } }