/// <summary> /// Instantiates a TraceSource and creates and adds listeners to the it. /// See Configuration.xml to change the level at which to log. /// </summary> private static TraceSource InitialiseTraceListener() { TraceSource theTraceSource = new TraceSource("2DTurnBasedGameFramework", LoadConfig.SourceLevel()); theTraceSource.Switch = new SourceSwitch("2DTurnBasedGameFramework", LoadConfig.SourceLevel().ToString()); // Text listener string loggerFilePath = Directory.GetCurrentDirectory() + "/Log.txt"; using StreamWriter sw = new StreamWriter(File.Create(loggerFilePath)) { AutoFlush = true }; TraceListener textListener = new TextWriterTraceListener(sw); theTraceSource.Listeners.Add(textListener); // BUG: Make textListener work... It generates the file, but does not seem to write to it. // Json listener string jsonLoggerFilePath = Directory.GetCurrentDirectory() + "/Log.json"; TraceListener jsonListener = new JsonTraceListener(jsonLoggerFilePath); theTraceSource.Listeners.Add(jsonListener); return(theTraceSource); }