Example #1
0
        private static void ConfigureConsoleLogger(String[] args)
        {
            var logger = TextWriterLogger.NewConsoleLogger();

            logger.Formatter         = new LogEntryFormatStringFormatter("[{category}] - {message}", null);
            logger.SeverityThreshold = (args.Contains("-d") || args.Contains("-debug")) ? LogSeverity.Debug : LogSeverity.Info;

            ConfigLogger.Instance.AddLogger("ConsoleLogger", logger);
        }
Example #2
0
        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
        }
Example #4
0
        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);
            }
        }