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); }
public void Retrieve_the_number_of_loggers() { var lp = new LogProvider(); var stringWriter = new StringWriter(); var sut = new TextWriterLogger(LogLevel.Informational, stringWriter); lp.AddLogger(sut); Assert.Equal(lp.GetLoggers().Count(), 1); }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyLoader" /> class. /// </summary> /// <param name="logger">The logger.</param> public AssemblyLoader(IMessageLogger logger) { this.textWriter = new TextWriterLogger(logger); this.appDomainHelper = new AppDomainHelper(); this.delegateTraceListener = new DelegateTraceListener( message => logger.SendMessage(TestMessageLevel.Informational, message)); this.proxyDomain = this.appDomainHelper.CreateInstance <ProxyLoader>(); }
public static BlokchainBatchProcessorService InitialiseBatchProcessorService(BlockchainRegistryProcessor blockchainRegistryProcessor, CloudTable workProcessRegistryTable, TextWriter logWriter, Web3 web3) { var workRegistryProcessInfoRepository = new ProcessInfoRepository(workProcessRegistryTable); var logger = new TextWriterLogger(logWriter); var latestBlockchainProcessorService = new LatestBlockBlockchainProcessProgressService(web3, ConfigurationSettings.StartProcessFromBlockNumber(), workRegistryProcessInfoRepository ); return(new BlokchainBatchProcessorService(blockchainRegistryProcessor, logger, latestBlockchainProcessorService, 200)); }
public void Specify_and_invalid_logId() { var lp = new LogProvider(); var stringWriter = new StringWriter(); var sut = new TextWriterLogger(LogLevel.Informational, stringWriter); lp.AddLogger(sut); var logSource = new StubLogSource(); lp.AddLogSourceToLoggers(logSource); Assert.Throws <ApplicationException>(() => logSource.InvalidLogId()); }
public static BlokchainBatchProcessorService InitialiseBlockchainBatchProcessorService(CloudTable workProcesssTable, CloudTable workProcessRegistryTable, WorkDataLogProcessor workProcessorService, TextWriter logWriter, Web3 web3) { var workProcessRepository = new ProcessInfoRepository(workProcesssTable); var workRegistryProcessInfoRepository = new ProcessInfoRepository(workProcessRegistryTable); var blockchainLogProcessor = new BlockchainLogProcessor(new [] { workProcessorService }, web3); var logger = new TextWriterLogger(logWriter); var childBlockchainProcessorService = new ChildBlockBlockchainProcessProgressService(workRegistryProcessInfoRepository, ConfigurationSettings.StartProcessFromBlockNumber(), workProcessRepository ); return(new BlokchainBatchProcessorService(blockchainLogProcessor, logger, childBlockchainProcessorService, 50)); }
public static BlockchainRegistryProcessor InitialiseBlockchainRegistryProcessor(TextWriter log, ICollector <RegistrationMessage> workRegisteredUnregisteredQueue, Web3 web3, AzureTable workRegistryTable) { var service = new RegistryService(web3, ConfigurationSettings.GetWorkRegistryContractAddress()); var workByteCodeMatcher = new ByteCodeMatcher(web3, new WorkContractDefinition()); var logger = new TextWriterLogger(log); var storageService = new WorkRegistryRepository(workRegistryTable); var registryQueue = new QueueRegistryProcessorService(new QueueRegistry(workRegisteredUnregisteredQueue)); var processingServices = new IRegistryProcessingService[] { storageService, registryQueue }; var blockchainRegistryProcessor = new BlockchainRegistryProcessor(web3, service, logger, processingServices, workByteCodeMatcher); return(blockchainRegistryProcessor); }
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 void Test_text_writer_logger() { var lp = new LogProvider(); var stringWriter = new StringWriter(); var sut = new TextWriterLogger(LogLevel.Informational, stringWriter); lp.AddLogger(sut); var logSource = new StubLogSource(); lp.AddLogSourceToLoggers(logSource); logSource.SayHelloTo("John"); lp.Dispose(); Assert.True(stringWriter.GetStringBuilder().ToString().Contains("John")); }
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) { /* * Logging may be performed two different ways. The first is legacy * and uses a logging delegate. This can give more control to the user * and remains to support older .NET implementations that already implemented * logging. The second is simply makes use of the existing logging classes * within libRETS and only requires specifying the log file name. */ RetsSession session = null; TextWriter logWriter = null; /* * Legacy method: */ try { session = new RetsSession( "http://demo.crt.realtors.org:6103/rets/login"); if (args.Length == 1) { logWriter = new StreamWriter(args[0]); } else { logWriter = TextWriter.Null; } session.LoggerDelegate = TextWriterLogger.CreateDelegate(logWriter); if (!session.Login("Joe", "Schmoe")) { Console.WriteLine("Invalid login"); Environment.Exit(1); } Console.WriteLine(".Net version: " + System.Environment.Version); LoginResponse login = session.GetLoginResponse(); Console.WriteLine("Member name: " + login.GetMemberName()); CapabilityUrls capabilityUrls = session.GetCapabilityUrls(); Console.WriteLine("Search URL: " + capabilityUrls.GetSearchUrl()); LogoutResponse logout = session.Logout(); Console.WriteLine("Billing info: " + logout.GetBillingInfo()); Console.WriteLine("Logout message: " + logout.GetLogoutMessage()); Console.WriteLine("Connect time: " + logout.GetConnectTime()); } finally { // Be sure to dispose RetsSession when finished, otherwise the // TextWriter Dispose() method may be called prior to RetsSession. if (session != null) { session.Dispose(); } logWriter.Close(); } /* * Preferred method. */ session = null; try { session = new RetsSession( "http://demo.crt.realtors.org:6103/rets/login"); if (args.Length == 1) { session.SetHttpLogName(args[0] + ".1"); } if (!session.Login("Joe", "Schmoe")) { Console.WriteLine("Invalid login"); Environment.Exit(1); } Console.WriteLine(".Net version: " + System.Environment.Version); LoginResponse login = session.GetLoginResponse(); Console.WriteLine("Member name: " + login.GetMemberName()); CapabilityUrls capabilityUrls = session.GetCapabilityUrls(); Console.WriteLine("Search URL: " + capabilityUrls.GetSearchUrl()); LogoutResponse logout = session.Logout(); Console.WriteLine("Billing info: " + logout.GetBillingInfo()); Console.WriteLine("Logout message: " + logout.GetLogoutMessage()); Console.WriteLine("Connect time: " + logout.GetConnectTime()); } finally { // Be sure to dispose RetsSession when finished, otherwise the // TextWriter Dispose() method may be called prior to RetsSession. if (session != null) { session.Dispose(); } } }