static async Task Main(string[] args) { ConsoleTraceListener consoleTraceListener = new ConsoleTraceListener(); consoleTraceListener.Name = "Main output"; Trace.Listeners.Add(consoleTraceListener); try { //TODO... arg error checking required. Trace.WriteLine($"Starting NutKitDotNet on {args[0]}:{args[1]}"); var address = args[0]; var port = Convert.ToInt32(args[1]); using var connection = new Connection(address, port); Controller controller = new Controller(connection); await controller.Process().ConfigureAwait(false); } catch (Exception ex) { Trace.WriteLine(ex.Message); Trace.WriteLine($"Exception Details: \n {ex.StackTrace}"); } finally { Trace.Flush(); Trace.Listeners.Remove(consoleTraceListener); consoleTraceListener.Close(); Trace.Close(); } }
static void InitializeTrace() { var logFolder = new DirectoryInfo(ConfigurationManager.AppSettings["LogFolder"]); if (!logFolder.Exists) { logFolder.Create(); } var consoleTraceListener = new ConsoleTraceListener { Filter = new EventTypeFilter(SourceLevels.All) }; var textWriterTraceListener = new TextWriterTraceListener( new StreamWriter(Path.Combine(logFolder.FullName, $"LyncLog-{DateTime.Now:yyyyMMdd-HHmmss}.log"))) { TraceOutputOptions = TraceOptions.DateTime, Filter = new EventTypeFilter(SourceLevels.All) }; Trace.Listeners.AddRange(new[] { consoleTraceListener, (TraceListener)textWriterTraceListener }); Trace.AutoFlush = true; Trace.TraceWarning("Lynclog started"); }
static void Main(string[] args) { var listener = new ConsoleTraceListener(); listener.Filter = new EventTypeFilter(SourceLevels.Warning); Trace.Listeners.Add(listener); StreamWriter writer = File.CreateText("log.txt"); writer.AutoFlush = true; Trace.Listeners.Add(new TextWriterTraceListener(writer)); Config config = GetConfig(); SelfCheck(config); var handleInputThread = new Thread(() => HandleInput(config)); handleInputThread.Start(); while (config.Repeat > 0) { Start(config); gameEnd.WaitOne(); client.Close(); } handleInputThread.Abort(); }
public void parseRequest() { try { String request = streamReadLine(inputStream); string[] tokens = request.Split(' '); if (tokens.Length != 3) { throw new Exception("invalid http request line"); } http_method = tokens[0].ToUpper(); http_url = tokens[1]; http_protocol_versionstring = tokens[2]; } catch (Exception f) { string sSource = "dotNET Sample App"; string sLog = "Application"; string sEvent = "Sample Event"; Debug.Listeners.Remove("Default"); TextWriterTraceListener logFile = new TextWriterTraceListener(@"C:\temp\log.log"); Trace.Listeners.Add(logFile); ConsoleTraceListener logConsole = new ConsoleTraceListener(); Trace.Listeners.Add(logConsole); Debug.WriteLine(sEvent = f.Message); Debug.Flush(); Trace.Flush(); } }
public void listen() { try { listener = new TcpListener(port); listener.Start(); while (is_active) { TcpClient s = listener.AcceptTcpClient(); HttpProcessor processor = new HttpProcessor(s, this); Thread thread = new Thread(new ThreadStart(processor.process)); thread.Start(); Thread.Sleep(1); } } catch (Exception f) { string sSource = "dotNET Sample App"; string sLog = "Application"; string sEvent = "Sample Event"; Debug.Listeners.Remove("Default"); TextWriterTraceListener logFile = new TextWriterTraceListener(@"C:\temp\log.log"); Trace.Listeners.Add(logFile); ConsoleTraceListener logConsole = new ConsoleTraceListener(); Trace.Listeners.Add(logConsole); Debug.WriteLine(sEvent = f.Message); Debug.Flush(); Trace.Flush(); } }
public TraceSource CreateTraceSource(string sourceName) { TraceSource ts = new TraceSource(sourceName); ts.Switch = new SourceSwitch("sourceSwitch"); ts.Switch.Level = SourceLevels.All; ts.Listeners.Remove("Default"); try { TextWriterTraceListener textListener = new TextWriterTraceListener(StreamWriter); textListener.Filter = new EventTypeFilter(SourceLevels.Information); ts.Listeners.Add(textListener); } catch (Exception) { ConsoleTraceListener consoleListener = new ConsoleTraceListener(); consoleListener.Filter = new EventTypeFilter(SourceLevels.Information); ts.Listeners.Add(consoleListener); } string logFileNameAbsolutePath = GetLogFileAbsolute(); ts.TraceInformation("InitTraceSource: log file " + logFileNameAbsolutePath); return(ts); }
static void Main(string[] args) { var consoleTracer = new ConsoleTraceListener(true); Trace.Listeners.Add(consoleTracer); consoleTracer.Name = "ManualFileSystemWatcherTrace"; string directory = (args.Length > 0 && args[0] != String.Empty) ? args[0] : @"C:\test\deleteme\logtest"; // ReSharper disable once RedundantJumpStatement CurrentFileListTest(directory); return; /* * WatcherFileListClasses.WatcherFileList w = new WatcherFileListClasses.WatcherFileList(new FileDirectoryWatcherSettings { }, null, 15000); * w.Start((list) => * { * foreach (var e in list) * { * System.Console.WriteLine($"{e.FileName} : {e.LastChanges}"); * } * * }); * * System.Console.WriteLine("Waiting"); * System.Console.ReadLine(); */ }
private static void goInProcess() { var start = DateTime.Now; void loadCommandLine() { var args = Environment.GetCommandLineArgs(); bool isVerbose = args.Contains("--verbose") || args.Contains("-v"); bool isQuiet = args.Contains("--quiet"); bool isColor = args.Contains("--color") || args.Contains("-c"); ConsoleTraceListener.SetStartupTime(start); var cliTraceListener = new ConsoleTraceListener(isVerbose, isQuiet, isColor); Log.AddListener(cliTraceListener); cliTraceListener.TraceEvents(TapInitializer.InitTraceListener.Instance.AllEvents.ToArray()); AppDomain.CurrentDomain.ProcessExit += (s, e) => cliTraceListener.Flush(); } TapInitializer.Initialize(); // This will dynamically load OpenTap.dll // loadCommandLine has to be called after Initialize // to ensure that we are able to load OpenTap.dll loadCommandLine(); wrapGoInProcess(); }
private void StartByUserInteractive(string[] args) { Console.ForegroundColor = ConsoleColor.Green; var ls = new ConsoleTraceListener(); if (args.Any(c => c == "-l")) { Trace.Listeners.Add(ls); } OnStart(args); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("all services are ready..."); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("press X to exit."); Console.ForegroundColor = ConsoleColor.Green; var key = Console.ReadKey(); while (true) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); if (key.Key == ConsoleKey.X) { break; } } Stop(); }
public ConsoleTraceListener() : base() { ConsoleTraceListener.AllocConsole(); Console.Beep(); Console.WriteLine(String.Format("{0} {1}", this.GetType().Name, "STARTED CONSOLE OUTPUT")); }
static void Main(string[] args) { mySource.Switch = new SourceSwitch("sourceSwitch", "Error"); mySource.Listeners.Remove("Default"); TextWriterTraceListener textListener = new TextWriterTraceListener("myListener.log"); textListener.TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Callstack; textListener.Filter = new EventTypeFilter(SourceLevels.Error); mySource.Listeners.Add(textListener); ConsoleTraceListener consoleListener = new ConsoleTraceListener(false); consoleListener.Filter = new EventTypeFilter(SourceLevels.Information); consoleListener.Name = "console"; mySource.Listeners.Add(consoleListener); Activity1(); mySource.Listeners["console"].Filter = new EventTypeFilter(SourceLevels.Critical); Activity2(); mySource.Switch.Level = SourceLevels.All; mySource.Listeners["console"].Filter = new EventTypeFilter(SourceLevels.Information); Activity3(); mySource.Close(); Console.Read(); }
protected override void Dispose(bool disposing) { if (disposing) { ConsoleTraceListener.FreeConsole(); } }
static Tracers() { SourceLevels singleSwitch = SourceLevels.Off; ConsoleTraceListener console = new ConsoleTraceListener(); SourceSwitch stringifySwitch = new SourceSwitch("stringify", "Verbose"); stringifySwitch.Level = singleSwitch; SourceSwitch parseSwitch = new SourceSwitch("parse", "Verbose"); parseSwitch.Level = singleSwitch; SourceSwitch normalizeSwitch = new SourceSwitch("normalize", "Verbose"); normalizeSwitch.Level = singleSwitch; Stringify = new TraceSource("stringify"); Stringify.Switch = stringifySwitch; Parse = new TraceSource("parse"); Parse.Switch = parseSwitch; Normalize = new TraceSource("normalize"); Normalize.Switch = normalizeSwitch; Parse.Listeners.Clear(); Normalize.Listeners.Clear(); Stringify.Listeners.Clear(); Parse.Listeners.Add(console); Normalize.Listeners.Add(console); Stringify.Listeners.Add(console); }
public int Main(int argc, string[] argv) { if (argc < 1) { Console.WriteLine("{app} [args]"); return -1; } int exitCode = 0; #if DESKTOP // CORECLR_TODO: Classic tracing var listener = new ConsoleTraceListener(); Trace.Listeners.Add(listener); Trace.AutoFlush = true; #endif string path = Path.GetFullPath(argv[0]); _container = new HostContainer(); AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve; var host = new RootHost(path); using (_container.AddHost(host)) { exitCode = ExecuteMain(path, argv.Skip(1).ToArray()); } AppDomain.CurrentDomain.AssemblyResolve -= OnAssemblyResolve; return exitCode; }
public static void WriteExpectedOutput(bool value) { RemoteExecutor.Invoke((_value) => { string message = "Write this message please"; bool setErrorStream = bool.Parse(_value); using (var stringWriter = new StringWriter()) { if (setErrorStream) { Console.SetError(stringWriter); } else { Console.SetOut(stringWriter); } using (var listener = new ConsoleTraceListener(useErrorStream: setErrorStream)) { listener.Write(message); string writerOutput = stringWriter.ToString(); Assert.Equal(message, writerOutput); Assert.DoesNotContain(Environment.NewLine, writerOutput); } } }, value.ToString()).Dispose(); }
public TraceWorker() { // simple trace listeners TraceListener tlConsole = new ConsoleTraceListener(); tlConsole.Filter = new EventTypeFilter(SourceLevels.All); // trace listener - file in solution folder TraceListener tlFile = new TextWriterTraceListener(new StreamWriter("ClassDemoLogFile.txt")); tlFile.Filter = new EventTypeFilter(SourceLevels.Warning); // trace listener - file in solution folder TraceListener tlXmlFile = new XmlWriterTraceListener(new StreamWriter("ClassDemoLogFile.xml")); tlXmlFile.Filter = new EventTypeFilter(SourceLevels.Warning); // This is deprecated in .Net Core does only exists by download a nuget packet 'Microsoft.Extensions.Logging.EventLog' //trace listener - windows event log TraceListener tlEventLog = new EventLogTraceListener("MyTrace"); tlEventLog.Filter = new EventTypeFilter(SourceLevels.Error); // My own trace listener tlOwn = new MyOwnTraceListener(); tlOwn.Filter = new EventTypeFilter(SourceLevels.All); Trace.Listeners.Add(tlConsole); Trace.Listeners.Add(tlFile); Trace.Listeners.Add(tlXmlFile); Trace.Listeners.Add(tlEventLog); Trace.Listeners.Add(tlOwn); }
/// <summary> /// Creates the Console trace listener from the current Settings, if a Listener Type is not provided then an instance of ConsoleTraceListener is returned. /// </summary> /// <returns>An Xml Log Recorder Listener instance.</returns> public override ILogRecorder CreateListener() { ILogRecorder listener = base.CreateListener(); if (listener == null) { listener = new ConsoleTraceListener(this); } return listener; }
static void Main(string[] args) { try { var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); LogFileWriter.Start($"{assemblyFolder}\\{DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss")}-Log.log", CancellationTokenSource.Token); _coordinator = new Coordinator <IMediaDiscovery, IMediaDestination>(new FileSystemSource(), new FileSystemDestination(), LogFileWriter); ConsoleTraceListener listener = new ConsoleTraceListener(); Trace.Listeners.Add(listener); CommandLine.Parser.Default.ParseArguments <Options>(args) .WithParsed(RunOptions) .WithNotParsed(HandleParseError); } catch (Exception ex) { CancellationTokenSource.Cancel(); Trace.WriteLine(ex.ToString()); LogFileWriter.WriteLine(ex.ToString()); Task.Delay(200); Environment.Exit((int)ExitCode.UnknownError); } Task.Delay(200); Environment.Exit((int)ExitCode.Success); }
static void Main(string[] args) { try { var consoleLogger = new ConsoleTraceListener(); Trace.Listeners.Add(consoleLogger); if (args.Count() < 2) { printUsage(); return; } PdfMerger.MergePDFs("output.pdf", args); } catch (Exception e) { Trace.TraceError(e.Message); } finally { Trace.WriteLine(""); Trace.WriteLine("Thanks for using Pdgmerger.exe"); Trace.WriteLine("https://github.com/aishvarya-sharma/Aish-Utilities"); } }
public static void WriteLineExpectedOutput(bool value) { RemoteExecutor.Invoke((_value) => { string message = "A new message to the listener"; bool setErrorStream = bool.Parse(_value); using (var stringWriter = new StringWriter()) { if (setErrorStream) { Console.SetError(stringWriter); } else { Console.SetOut(stringWriter); } using (var listener = new ConsoleTraceListener(useErrorStream: setErrorStream)) { listener.WriteLine(message); Assert.Contains(message, stringWriter.ToString() + Environment.NewLine); } } }, value.ToString()).Dispose(); }
public TraceLogger(string fileName) { Guard.ArgumentNotEmpty(() => fileName); _traceSource = new TraceSource("InSearch"); _traceSource.Switch = new SourceSwitch("LogSwitch", "Error"); _traceSource.Listeners.Remove("Default"); var console = new ConsoleTraceListener(false); console.Filter = new EventTypeFilter(SourceLevels.All); console.Name = "console"; var textListener = new TextWriterTraceListener(fileName); textListener.Filter = new EventTypeFilter(SourceLevels.All); textListener.TraceOutputOptions = TraceOptions.DateTime; _traceSource.Listeners.Add(console); _traceSource.Listeners.Add(textListener); // Allow the trace source to send messages to // listeners for all event types. Currently only // error messages or higher go to the listeners. // Messages must get past the source switch to // get to the listeners, regardless of the settings // for the listeners. _traceSource.Switch.Level = SourceLevels.All; }
private void SetTraceFilter(string /*!*/ arg, bool enable) { string[] categories = arg.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); if (categories.Length == 0 && !enable) { Debug.Listeners.Clear(); return; } if (_debugListener == null) { _debugListener = new ConsoleTraceListener { IndentSize = 4, Filter = new CustomTraceFilter { EnableAll = categories.Length == 0 } }; Debug.Listeners.Add(_debugListener); } foreach (var category in categories) { ((CustomTraceFilter)_debugListener.Filter).Categories[category] = enable; } }
static async Task Main(string[] args) { System.Console.WriteLine("Starting..."); #if DEBUG ConsoleTraceListener consoleTraceListener = new ConsoleTraceListener(); Trace.Listeners.Add(consoleTraceListener); #endif String fileName = Path.Join(AssemblyDirectory, "tulips.jpg"); if (args.Length > 0) { fileName = args[0]; } _inputFileInfo = new FileInfo(fileName); if (!_inputFileInfo.Exists) { System.Console.WriteLine(String.Format("File '{0}' does not exist. Please provide a valid file name as input parameter.", _inputFileInfo.FullName)); return; } Trace.WriteLine(String.Format("Working on file {0}", _inputFileInfo.FullName)); await Run(); System.Console.WriteLine("Press any key to continue:"); System.Console.ReadKey(); }
//static void ClearFromOldInstall() //{ // //The dll search path searches the application directory 1st // //before searching the directory specified in SetDllDirectory // //To ensure we get the vJoyInterface that matches the installed // //driver, we delete the vJoyInterface.dll that was bundled in // //older versions // if (File.Exists("vJoyInterface.dll")) // { // File.Delete("vJoyInterface.dll"); // } //} static void SetupLoggin() { if (File.Exists("Pad2vJoy.log")) { File.Delete("Pad2vJoy.log"); } Trace.Listeners.Clear(); TextWriterTraceListener twtl = new TextWriterTraceListener("Pad2vJoy.log"); twtl.Writer.NewLine = "\n"; twtl.Name = "TextLogger"; twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime; ConsoleTraceListener ctl = new ConsoleTraceListener(false); ctl.TraceOutputOptions = TraceOptions.DateTime; //Trace.Listeners.Add(twtl); Trace.Listeners.Add(ctl); Trace.AutoFlush = true; Trace.WriteLine("Trace Active"); }
private static void ConfigureTrace() { var listener = new ConsoleTraceListener(); Trace.Listeners.Add(listener); Trace.AutoFlush = true; }
static void Main() { DelimitedListTraceListener listener = new DelimitedListTraceListener("../../Tracing/CorrelationLog.log"); listener.Delimiter = "|"; ConsoleTraceListener console = new ConsoleTraceListener(); listener.TraceOutputOptions |= TraceOptions.LogicalOperationStack; console.TraceOutputOptions |= TraceOptions.LogicalOperationStack; Trace.Listeners.Clear(); Trace.Listeners.Add(listener); Trace.Listeners.Add(console); Trace.CorrelationManager.StartLogicalOperation("Main Method Calls"); Trace.TraceInformation("Starting processing threads..."); Thread[] threads = new Thread[2]; threads[0] = new Thread(new ThreadStart(ProcessOrders)); threads[1] = new Thread(new ThreadStart(ShipProcessedOrders)); threads[0].Start(); threads[1].Start(); //Block until each thread returns threads[0].Join(); threads[1].Join(); Trace.CorrelationManager.StopLogicalOperation(); Console.Read(); }
public static ConsoleTraceListener RegisterConsoleListener() { ConsoleTraceListener listener = new ConsoleTraceListener(); Trace.Listeners.Add(listener); return(listener); }
public LibcSecureMemoryAllocatorTest() { Trace.Listeners.Clear(); var consoleListener = new ConsoleTraceListener(); Trace.Listeners.Add(consoleListener); Debug.WriteLine("LibcSecureMemoryAllocatorTest ctor"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { libc = new LinuxLibcLP64(); libcSecureMemoryAllocator = new LinuxSecureMemoryAllocatorLP64((LinuxLibcLP64)libc); linuxSecureMemoryAllocatorMock = new Mock <LinuxSecureMemoryAllocatorLP64>() { CallBase = true }; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { libc = new MacOSLibcLP64(); libcSecureMemoryAllocator = new MacOSSecureMemoryAllocatorLP64((MacOSLibcLP64)libc); macOsSecureMemoryAllocatorMock = new Mock <MacOSSecureMemoryAllocatorLP64>() { CallBase = true }; } else { libc = null; libcSecureMemoryAllocator = null; macOsSecureMemoryAllocatorMock = null; } }
public void InitTraceListen() { string appdir = AppDomain.CurrentDomain.BaseDirectory; string logfile = appdir + "\\log\\logfile.log"; if (!Directory.Exists(appdir + "\\log")) { Directory.CreateDirectory(appdir + "\\log"); } if (File.Exists(logfile)) { Directory.Delete(appdir + "\\log", true); Directory.CreateDirectory(appdir + "\\log"); var log = File.Create(logfile); log.Close(); } else { var log = File.Create(logfile); } TextWriterTraceListener twtl = new TextWriterTraceListener(logfile) { TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime }; ConsoleTraceListener ctl = new ConsoleTraceListener(false) { TraceOutputOptions = TraceOptions.DateTime }; Trace.Listeners.Add(twtl); Trace.Listeners.Add(ctl); Trace.AutoFlush = true; }
public static void Generate(String basedir) { Trace.Listeners.Clear(); String dn = String.Format(@"{0}\LOG\{1}", basedir, Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)); if (!Directory.Exists(dn)) { Directory.CreateDirectory(dn); } TextWriterTraceListener twtl = new TextWriterTraceListener(String.Format(@"{0}\{1:yyyMMdd_HHmmss}.log", dn, DateTime.Now)); twtl.Name = "TextLogger"; twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime | TraceOptions.Timestamp; ConsoleTraceListener ctl = new ConsoleTraceListener(false); ctl.TraceOutputOptions = TraceOptions.DateTime; Trace.Listeners.Add(twtl); Trace.Listeners.Add(ctl); Trace.AutoFlush = true; PrintDateTime(); }
/// <summary> /// Starts the trace listners. /// </summary> public static void StartTraceListners(string logFilePrefix = "RulePerf") { string logFilePath = "{1}-{0}.log".FormatWith(DateTime.Now.ToString("yyyy-MM-ddThh-mm-ssZ"), logFilePrefix); logFilePath = System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, logFilePath); TextWriterTraceListener textWriterTraceListener = new TextWriterTraceListener(logFilePath, "logListener"); ConsoleTraceListener consoleTraceListener = new ConsoleTraceListener(); ////Trace.Listeners.Clear(); if (!Trace.Listeners.Contains(textWriterTraceListener.GetType(), textWriterTraceListener.Name)) { Trace.Listeners.Add(textWriterTraceListener); } else { textWriterTraceListener.Dispose(); } if (!Trace.Listeners.Contains(consoleTraceListener.GetType())) { Trace.Listeners.Add(consoleTraceListener); } else { consoleTraceListener.Dispose(); } Trace.AutoFlush = true; }
private static void Main(string[] args) { // logger XmlConfigurator.Configure(); if (!Environment.UserInteractive) { Run(new Program()); } else { var consoleTraceListener = new ConsoleTraceListener(); consoleTraceListener.Filter = new EventTypeFilter(SourceLevels.Information); Trace.Listeners.Add(consoleTraceListener); _remoteSessionProcess = OpenService(typeof(RemoteSessionProcess)); _localFileStorage = OpenService(typeof(FileStorage)); Console.WriteLine("press any key to exit..."); Console.ReadKey(); CloseService(ref _remoteSessionProcess); CloseService(ref _localFileStorage); } }
static TraceListener AddDefaultConsoleTraceListener(TraceSource source) { var listener = new ConsoleTraceListener {Name = "MassTransit"}; source.Listeners.Add(listener); return listener; }
private void InitializeConsoleRedirect() { var consoleLogging = new ConsoleLogging(); _consoleRedirector = new ConsoleRedirector(); _consoleRedirector.Logging = consoleLogging; _consoleTraceListener = new ConsoleTraceListener(); _consoleTraceListener.Logging = consoleLogging; // Set console outputs (this will redirect Console.Write* output to the cryengine console) Console.SetOut(_consoleRedirector); Console.SetError(_consoleRedirector); // Add our trace listener (this will redirect Trace.* output to the cryengine console) Trace.Listeners.Add(_consoleTraceListener); }
public void WhenExecutingRequest_ThenTracesInformationHeaders() { var listener = new ConsoleTraceListener(); TracerExtensibility.AddListener(SourceName.For<TracingChannel>(), listener); TracerExtensibility.SetTracingLevel(SourceName.For<TracingChannel>(), SourceLevels.All); var config = HttpHostConfiguration.Create() .UseJsonNet() .AddMessageHandlers(typeof(TracingChannel)); using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", true, config)) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query<Product>().Skip(1).Take(1).ToList(); Assert.Equal(1, products.Count); Assert.Equal(2, products[0].Id); } listener.Flush(); }