static CDRLogger() { // Gebruik eigen formatter BitFactory.Logging.Logger.DefaultFormatterClass = typeof(LogEntryCDRFormatter); // We gebruiken de application naam als filename voor het log bestand. filename = String.Format(".\\{0}.log", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name); if (File.Exists(filename)) { // We voegen info toe om te vertellen dat dit een nieuwe restart is van de applicatie using (StreamWriter w = File.AppendText(filename)) { w.WriteLine(); w.WriteLine(String.Format("Application started at {0:yyyy-MM-dd HH:mm:ss.fff}", DateTime.Now)); w.WriteLine(); } //using } //if file exists Logger = new CompositeLogger(); // voeg altijd memory logger toe memoryLogger = new MemoryLogger(1000); // capacity van 1000 regels maximaal daarna worden de oude overschreven Logger.AddLogger("MemoryLogger", memoryLogger); fileLogger = new FileLogger(filename); Logger.AddLogger("FileLogger", fileLogger); }
private void ApplyLogger() { ILoggerSettingsSection section = this.GetLoggerSettings(); ICompositeLogger helper = new CompositeLogger(new CompositeLoggerSettings(section)); helper.AddLogger(new ConsoleLogger(new ConsoleLoggerSettings(section))); helper.AddLogger(new PersistentLogger(new PersistentLoggerSettings(section))); this.logger = helper; }
static void Main(string[] args) { AutomationHelper.AutomationJob.Start(args); string defaultLogFilename = ConfigurationManager.AppSettings["LogFileName"]; string logfilename = string.Format(@"{0}\{1}_{2}_{4}{3}", ConfigurationManager.AppSettings["LogFilePath"], Path.GetFileNameWithoutExtension(defaultLogFilename), Environment.MachineName, Path.GetExtension(defaultLogFilename), DateTime.Today.ToString("MMMddyyyy", CultureInfo.InvariantCulture)); _logger.AddLogger("file", new FileLogger(logfilename)); _logger.AddLogger("debug", new DebugLogger()); _logger.AddLogger("console", TextWriterLogger.NewConsoleLogger()); string currentFileName = AutomationHelper.AutomationJob.GetArgument("CurrentFileName"); try { _logger.LogInfo("LogFileName:" + logfilename); _logger.LogInfo("CurrentFileName:" + currentFileName); string oldIpAddress = string.Empty; try { oldIpAddress = File.ReadAllText(string.Format(@".\{0}", currentFileName)); } catch (Exception) { } string currentIpAddress = GetPublicIpAddress(); _logger.LogInfo("Old IP Address:" + oldIpAddress); _logger.LogInfo("Current IP Address:" + currentIpAddress); if (!string.IsNullOrWhiteSpace(currentIpAddress) && oldIpAddress != currentIpAddress) { Skywolf.Client.Utility.SendReportMail(null, "*****@*****.**", "Heart Lake Update", string.Join(".", currentIpAddress.Split(new char[] { '.' }).Select(p => (Convert.ToInt32(p) + 1).ToString()).ToArray())); File.WriteAllText(string.Format(@".\{0}", currentFileName), currentIpAddress); } } catch (Exception ex) { Skywolf.Client.Utility.SendReportMail(null, "*****@*****.**", string.Format("IP Address Detect Error - {0:yyyyMMdd hh:mm:ss}", DateTime.Now), ex.Message + ex.StackTrace); } }
public TobiLoggerFacade() { #if (DEBUG) //PresentationTraceSources.SetTraceLevel(obj, PresentationTraceLevel.High) #endif PresentationTraceSources.ResourceDictionarySource.Listeners.Add(new LoggerFacadeTraceListener(this)); PresentationTraceSources.ResourceDictionarySource.Switch.Level = SourceLevels.All; PresentationTraceSources.DataBindingSource.Listeners.Add(new LoggerFacadeTraceListener(this)); PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Error; #if (false && DEBUG) // not very useful (misses the TAB control) PresentationTraceSources.DataBindingSource.Listeners.Add(new BindingErrorAdornerTraceListener(false)); #endif PresentationTraceSources.DependencyPropertySource.Listeners.Add(new LoggerFacadeTraceListener(this)); PresentationTraceSources.DependencyPropertySource.Switch.Level = SourceLevels.All; PresentationTraceSources.DocumentsSource.Listeners.Add(new LoggerFacadeTraceListener(this)); PresentationTraceSources.DocumentsSource.Switch.Level = SourceLevels.All; PresentationTraceSources.MarkupSource.Listeners.Add(new LoggerFacadeTraceListener(this)); PresentationTraceSources.MarkupSource.Switch.Level = SourceLevels.All; PresentationTraceSources.NameScopeSource.Listeners.Add(new LoggerFacadeTraceListener(this)); PresentationTraceSources.NameScopeSource.Switch.Level = SourceLevels.All; //StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput()); //standardOutput.AutoFlush = true; //Console.SetOut(standardOutput); //StreamWriter standardErr = new StreamWriter(Console.OpenStandardError()); //standardErr.AutoFlush = true; //Console.SetError(standardErr); //if (File.Exists(ApplicationConstants.LOG_FILE_PATH)) //{ // // Remark: the following logging messages go to the System.Out, and that's it (not to any file target). We initialize file redirect later on (see below). // Console.WriteLine("Deleting log file [" + ApplicationConstants.LOG_FILE_PATH + "]..."); // File.Delete(ApplicationConstants.LOG_FILE_PATH); // Console.WriteLine("File deleted [" + ApplicationConstants.LOG_FILE_PATH + "]."); // Thread.Sleep(100); //} #if (BITFACTORY) Debug.Listeners.Add(new BitFactoryLoggerTraceListener(this)); Trace.Listeners.Add(new BitFactoryLoggerTraceListener(this)); m_Logger = new CompositeLogger(); Logger consoleLogger = TextWriterLogger.NewConsoleLogger(); m_Logger.AddLogger("console", consoleLogger); consoleLogger.Formatter = new BitFactoryLoggerLogEntryFormatter(); #endif #if (BITFACTORY) Logger fileLogger = new FileLogger(UserInterfaceStrings.LOG_FILE_PATH); m_Logger.AddLogger("file", fileLogger); fileLogger.Formatter = new BitFactoryLoggerLogEntryFormatter(); #else // Remark: we could set DiagnosticsConfiguration.LogFileName // and benefit from DefaultTraceListener's built-in support for output to log file, // but unfortunately the WriteToLogFile() method opens and closes the file // for each Write operation, which obviously is a massive performance bottleneck. //m_FileWriter = File.CreateText(UserInterfaceStrings.LOG_FILE_PATH); FileStream fileStream = null; try { fileStream = new FileStream(ApplicationConstants.LOG_FILE_PATH, FileMode.Create, FileAccess.Write, FileShare.Read); } catch (Exception ex) { MessageBox.Show("1) Press the OK button (the file explorer will open to the file location: [" + ApplicationConstants.LOG_FILE_PATH + "]).\n\n2) Then delete [" + ApplicationConstants.LOG_FILE_NAME + "].\n\n3) Then launch Tobi again."); //MessageBox.Show(ex.Message); string dir = Path.GetDirectoryName(ApplicationConstants.LOG_FILE_PATH); // Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) // Shell.ExecuteShellProcess() var process = new Process { StartInfo = { FileName = dir, RedirectStandardError = false, // We can't redirect messages when shell-execute RedirectStandardOutput = false, // We can't redirect messages when shell-execute UseShellExecute = true, WindowStyle = ProcessWindowStyle.Normal, Arguments = "" } }; process.Start(); throw ex; } #if (false && DEBUG) // We want clickable code line numbers in the debugger output window, but we don't want to spam the log file with this info. m_FileWriter = new CodeLocationTextWriter(new StreamWriter(fileStream)); #else m_FileWriter = new StreamWriter(fileStream) { AutoFlush = true }; #endif var listener = new TextWriterTraceListener(m_FileWriter) { // TraceOutputOptions = TraceOptions.DateTime // | TraceOptions.LogicalOperationStack // | TraceOptions.Timestamp //#if (DEBUG) // | TraceOptions.Callstack //#endif }; // Works for DEBUG too, no need for a second set of listeners Trace.Listeners.Add(listener); //TODO: this is a massive hack as we needed to change "internal" to "public" in the MEF source code !! (how else to do this though ?) TraceSourceTraceWriter.Source.Listeners.Add(listener); #if (DEBUG) var systemOut = new CodeLocationTextWriter(Console.Out); #else var systemOut = Console.Out; #endif //Trace.Listeners.Add(new TextWriterTraceListener(systemOut)); #if (DEBUG) var systemErr = new CodeLocationTextWriter(Console.Error); #else var systemErr = Console.Error; #endif //Trace.Listeners.Add(new TextWriterTraceListener(systemErr)); var compositeOut = new CompositeTextWriter(new[] { m_FileWriter, systemOut }); Console.SetOut(compositeOut); var compositeErr = new CompositeTextWriter(new[] { m_FileWriter, systemErr }); Console.SetError(compositeErr); #endif }
static void Main(string[] args) { AutomationHelper.AutomationJob.Start(args); string defaultLogFilename = ConfigurationManager.AppSettings["LogFileName"]; string logfilename = string.Format(@"{0}\{1}_{2}_{4}{3}", ConfigurationManager.AppSettings["LogFilePath"], Path.GetFileNameWithoutExtension(defaultLogFilename), Environment.MachineName, Path.GetExtension(defaultLogFilename), DateTime.Today.ToString("MMMddyyyy", CultureInfo.InvariantCulture)); _logger.AddLogger("file", new FileLogger(logfilename)); _logger.AddLogger("debug", new DebugLogger()); _logger.AddLogger("console", TextWriterLogger.NewConsoleLogger()); string period = AutomationHelper.AutomationJob.GetArgument("period"); string adjustedvalue = AutomationHelper.AutomationJob.GetArgument("adjustedvalue"); string startFrom = AutomationHelper.AutomationJob.GetArgument("StartFrom"); string marketDataDUrl = AutomationHelper.AutomationJob.GetArgument("MarketDataDSkywolfHttp"); string marketDataMUrl = AutomationHelper.AutomationJob.GetArgument("MarketDataMSkywolfHttp"); string marketDataWUrl = AutomationHelper.AutomationJob.GetArgument("MarketDataWSkywolfHttp"); string marketDataMNUrl = AutomationHelper.AutomationJob.GetArgument("MarketDataMNSkywolfHttp"); string priorityStart = AutomationHelper.AutomationJob.GetArgument("PriorityStart"); string priorityEnd = AutomationHelper.AutomationJob.GetArgument("PriorityEnd"); bool isAdjustedValue = false; bool.TryParse(adjustedvalue, out isAdjustedValue); int iStartFrom = 0; int.TryParse(startFrom, out iStartFrom); int iPriorityStart = 0; int iPriorityEnd = 0; int.TryParse(priorityStart, out iPriorityStart); int.TryParse(priorityEnd, out iPriorityEnd); try { _logger.LogInfo("LogFileName:" + logfilename); _logger.LogInfo("Period:" + period); _logger.LogInfo("AdjustedValue:" + isAdjustedValue.ToString()); _logger.LogInfo("StartFrom:" + iStartFrom); _logger.LogInfo("PriorityStart:" + iPriorityStart); _logger.LogInfo("PriorityEnd:" + iPriorityEnd); _logger.LogInfo("MarketDataDUrl:" + marketDataDUrl); _logger.LogInfo("MarketDataMUrl:" + marketDataMUrl); _logger.LogInfo("MarketDataWUrl:" + marketDataWUrl); _logger.LogInfo("MarketDataMNUrl:" + marketDataMNUrl); MarketDataHandler marketData = new MarketDataHandler(period, isAdjustedValue, iPriorityStart, iPriorityEnd); marketData.Update(iStartFrom); string title = string.Empty; if (isAdjustedValue) { title = string.Format("Alpha Vantage Market Data ({0} Adjusted) {1}-{2} Done", period, iPriorityStart, iPriorityEnd); } else { title = string.Format("Alpha Vantage Market Data ({0}) {1}-{2} Done", period, iPriorityStart, iPriorityEnd); } Skywolf.Client.Utility.SendReportMail(null, "*****@*****.**", title, string.Empty); } catch (Exception ex) { _logger.LogError(ex.Message); _logger.LogError(ex.StackTrace); Skywolf.Client.Utility.SendReportMail(null, "*****@*****.**", string.Format("Alpha Vantage Market Data ({0}) {1}-{2} Error", period, iPriorityStart, iPriorityEnd), ex.Message + ex.StackTrace); } finally { AutomationHelper.AutomationJob.End(logfilename); } }
static void Main(string[] args) { ServerArgs serverArgs = new ServerArgs().Parse(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.json")).Parse(args).Validate(); EventLogOutputPipe eventLogOutputPipe = new EventLogOutputPipe(); CompositeLogger logger = new CompositeLogger(); if (serverArgs.EnableEventLog) { logger.AddLogger(new Logger(eventLogOutputPipe, eventLogOutputPipe)); } if (serverArgs.EnablePipeLog) { try { NamedPipeServer namedPipe = new NamedPipeServer(serverArgs.LogPipeName); Logger namedPipeLogger = new Logger(namedPipe, namedPipe); logger.AddLogger(namedPipeLogger); } catch (Exception e) { logger.LogError("Failed to initialize named pipe logger: " + e.Message); } } if (serverArgs.Errors.Count > 0) { logger.LogError("Server arguments had errors."); foreach (string error in serverArgs.Errors) { logger.LogError(error); } return; } // Load external modules PowerShellRunspace runspace = new PowerShellRunspace(logger); foreach (string externalModule in serverArgs.ExternalModules) { GeneratedModule module = new GeneratedModule(runspace); module.ModulePath = externalModule; CommandExecutionResult result = module.Load(); if (result != null && result.HadErrors) { logger.LogError(String.Format(CultureInfo.CurrentCulture, "Failed to load extra module: {0}", externalModule)); result.LogErrors(logger); return; } } // Start test server JsonRpcPipe jsonRpcPipe = new JsonRpcPipe(new StandardInputPipe(), new StandardOutputPipe()); LiveTestServer server = new LiveTestServer(new LiveTestServerStartParams() { Logger = logger, Input = jsonRpcPipe, Output = jsonRpcPipe, CredentialFactory = new LiveTestCredentialFactory(), RunspaceManager = runspace, ModulePath = serverArgs.ModulePath, TracingManager = new ServiceTracingManager(), SpecificationPaths = serverArgs.SpecificationPaths, ObjectTransforms = serverArgs.GetTransforms() }); try { server.RunAsync().Wait(); } catch (Exception ex) { logger.LogError("Failed to start server: " + ex.ToString()); } // Wait until server exits (usually means the server ran into an internal error) while (server.IsRunning) { Thread.Sleep(2); } }