상속: System.IO.StreamWriter
예제 #1
0
        public static bool OpenLogFile()
        {
            try
            {
                CloseLogFile();

                string curpath = Path.Combine(System.Windows.Forms.Application.StartupPath, @"temp");// Path.GetFullPath(".");//Path.GetTempPath();
                LogFilePath = curpath;
                if (!Directory.Exists(curpath))
                {
                    Directory.CreateDirectory(curpath);
                }
                date                       = DateTime.Now.ToString("yyyy-MM");
                LogFileName                = "shadowsocks_" + date + ".log";
                LogFile                    = Path.Combine(curpath, LogFileName);
                _logFileStream             = new FileStream(LogFile, FileMode.Append);
                _logStreamWriter           = new StreamWriterWithTimestamp(_logFileStream);
                _logStreamWriter.AutoFlush = true;
                Console.SetOut(_logStreamWriter);
                Console.SetError(_logStreamWriter);

                return(true);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
예제 #2
0
 public static bool OpenLogFile()
 {
     try
     {
         string curpath = Path.Combine(System.Windows.Forms.Application.StartupPath, @"temp");// Path.GetFullPath(".");//Path.GetTempPath();
         if (!Directory.Exists(curpath))
         {
             Directory.CreateDirectory(curpath);
         }
         date = DateTime.Now.ToString("yyyy-MM");
         LogFile = Path.Combine(curpath, "shadowsocks_" + date + ".log");
         FileStream fs = new FileStream(LogFile, FileMode.Append);
         StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(fs);
         sw.AutoFlush = true;
         Console.SetOut(sw);
         Console.SetError(sw);
         
         return true;
     }
     catch (IOException e)
     {
         Console.WriteLine(e.ToString());
         return false;
     }
 }
예제 #3
0
        public static bool OpenLogFile()
        {
            try
            {
                CloseLogFile();

                if (save_to_file)
                {
                    var newDate = DateTime.Now.ToString("yyyy-MM");
                    LogFileName      = $@"shadowsocks_{newDate}.log";
                    LogFile          = Utils.GetTempPath(LogFileName);
                    _logFileStream   = new FileStream(LogFile, FileMode.Append);
                    _logStreamWriter = new StreamWriterWithTimestamp(_logFileStream)
                    {
                        AutoFlush = true
                    };
                    Console.SetOut(_logStreamWriter);
                    Console.SetError(_logStreamWriter);
                    date = newDate;
                    CompressOldLogFile();
                }
                else
                {
                    Console.SetOut(DefaultOut);
                    Console.SetError(DefaultError);
                }

                return(true);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
예제 #4
0
        private static void CloseLogFile()
        {
            _logStreamWriter?.Dispose();
            _logFileStream?.Dispose();

            _logStreamWriter = null;
            _logFileStream   = null;
        }
예제 #5
0
        public static void CloseLogFile(bool closed = true)
        {
            if (closed)
            {
                enabled = false;
            }
            _logStreamWriter?.Dispose();
            _logFileStream?.Dispose();

            _logStreamWriter = null;
            _logFileStream   = null;
        }
예제 #6
0
        private static void CloseLogFile()
        {
            if (_logStreamWriter != null)
            {
                _logStreamWriter.Dispose();
                _logStreamWriter = null;
            }

            if (_logFileStream != null)
            {
                _logFileStream.Dispose();
                _logFileStream = null;
            }
        }
예제 #7
0
        public static bool OpenLogFile()
        {
            try
            {
                LogFile = Path.Combine(Path.GetTempPath(), "shadowsocks.log");
                var fs = new FileStream(LogFile, FileMode.Append);
                var sw = new StreamWriterWithTimestamp(fs) {AutoFlush = true};
                Console.SetOut(sw);
                Console.SetError(sw);

                return true;
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return false;
            }
        }
예제 #8
0
        public static bool OpenLogFile()
        {
            try
            {
                LogFile = Utils.GetTempPath("shadowsocks.log");
                FileStream fs = new FileStream(LogFile, FileMode.Append);
                StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(fs);
                sw.AutoFlush = true;
                Console.SetOut(sw);
                Console.SetError(sw);

                return(true);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
예제 #9
0
        public static bool OpenLogFile()
        {
            try
            {
                string temppath = Utils.GetTempPath();
                LogFile = Path.Combine(temppath, "shadowsocks.log");
                FileStream fs = new FileStream(LogFile, FileMode.Append);
                StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(fs);
                sw.AutoFlush = true;
                Console.SetOut(sw);
                Console.SetError(sw);

                return true;
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return false;
            }
        }
예제 #10
0
        public static bool OpenLogFile()
        {
            try
            {
                LogFilePath = Path.Combine(Path.GetTempPath(), "shadowsocks.log");

                _fs           = new FileStream(LogFilePath, FileMode.Append);
                _sw           = new StreamWriterWithTimestamp(_fs);
                _sw.AutoFlush = true;
                Console.SetOut(_sw);
                Console.SetError(_sw);

                return(true);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
예제 #11
0
        public static bool OpenLogFile()
        {
            try
            {
                string curpath = Path.Combine(System.Windows.Forms.Application.StartupPath, @"temp");// Path.GetFullPath(".");//Path.GetTempPath();
                if (!Directory.Exists(curpath))
                {
                    Directory.CreateDirectory(curpath);
                }
                LogFile = Path.Combine(curpath, "shadowsocks.log");
                FileStream fs = new FileStream(LogFile, FileMode.Append);
                StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(fs);
                sw.AutoFlush = true;
                Console.SetOut(sw);
                Console.SetError(sw);

                return(true);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
예제 #12
0
        public static bool OpenLogFile()
        {
            try
            {
                CloseLogFile();

                string new_date = DateTime.Now.ToString("yyyy-MM");
                LogFileName                = "shadowsocks_" + new_date + ".log";
                LogFile                    = AppdataPath.Current.GetFilePath(LogFileName);
                _logFileStream             = new FileStream(LogFile, FileMode.Append);
                _logStreamWriter           = new StreamWriterWithTimestamp(_logFileStream);
                _logStreamWriter.AutoFlush = true;
                Console.SetOut(_logStreamWriter);
                Console.SetError(_logStreamWriter);
                date = new_date;

                return(true);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
예제 #13
0
        public static bool OpenLogFile()
        {
            try
            {
                LogFilePath = Utils.GetTempPath("shadowsocks.log");

                _fs = new FileStream(LogFilePath, FileMode.Append);
                _sw = new StreamWriterWithTimestamp(_fs);
                _sw.AutoFlush = true;
                Console.SetOut(_sw);
                Console.SetError(_sw);

                return true;
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                return false;
            }
        }