System.IO.FileInfo.CreateText C# (CSharp) Method

CreateText() public method

public CreateText ( ) : StreamWriter
return StreamWriter
        public StreamWriter CreateText()
        {
            return new StreamWriter(FullPath, append: false);
        }

Same methods

FileInfo::CreateText ( ) : System.IO.StreamWriter

Usage Example

        public static void _Main(string[] args)
        {
            Trace.WriteLine("start");

              var logname = string.Format("{0}_{1}.{2}", "unhand", DateTime.Now.ToString("MMMdd-hhmmss-fffffff"), "log");
              var listenerFile = new System.IO.FileInfo(logname);
              listenerWriter = listenerFile.CreateText();
              listener = new TextWriterTraceListener(listenerWriter);
              Trace.Listeners.Add(listener);
              //Trace.Listeners.Add(new TextWriterTraceListener(Console.Error));
              Trace.AutoFlush = true;

              AppDomain currentDomain = AppDomain.CurrentDomain;
              currentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhand_Handler);

              try
              {
            Trace.WriteLine("throw 1");
            throw new Exception("1");
              }
              catch (Exception e)
              {
            Trace.WriteLine($"Catch clause caught : {e.Message} \n");
              }
              Trace.WriteLine("throw 2");
              throw new Exception("2");
              //Trace.WriteLine("end");
        }
All Usage Examples Of System.IO.FileInfo::CreateText