コード例 #1
0
ファイル: Logger.cs プロジェクト: yukseljunk/wps
        public static void ResetLogFile()
        {
            var data = Environment.NewLine + "DateTime\t\tThreadId\tDescription";

            data += Environment.NewLine + "--------\t\t--------\t-----------";
            data += Environment.NewLine + OneLine("Start") + Environment.NewLine;

            var fileReaderWriter = new FileReaderWriter();

            _logFilePath = Path.GetFullPath(Path.Combine(Helper.AssemblyDirectory,
                                @"..\..\logs\log_" + DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year + "." + DateTime.Now.Hour + "." + DateTime.Now.Minute + "." + DateTime.Now.Second + ".txt"));
            fileReaderWriter.WriteFile(LogFilePath, data);
        }
コード例 #2
0
ファイル: Logger.cs プロジェクト: yukseljunk/wps
        public static void LogExceptions(Exception exception)
        {
            if (exception == null) return;
            var data = OneLine("EXCEPTION ENCOUNTERED")+Environment.NewLine;

            var webException = exception as WebException;
            if (exception.InnerException !=null && webException == null)
            {
                webException = exception.InnerException as WebException;
            }
            if(webException!=null)
            {
                if (webException.Status == WebExceptionStatus.ProtocolError)
                {
                    using (var resp = webException.Response)
                    {
                        try
                        {
                            using (var sr = new StreamReader(resp.GetResponseStream()))
                            {
                                data += OneLine("Web Exception Details:" + Environment.NewLine + sr.ReadToEnd()) + Environment.NewLine;

                                sr.Close();
                            }

                        }
                        catch (Exception exc)
                        {
                            data += OneLine("Another exception: " + exc.Message) + Environment.NewLine;
                        }
                        resp.Close();
                    }
                }
            }

            data += OneLine(exception.Message + Environment.NewLine + exception.StackTrace);
            if(exception.InnerException!=null)
            {
                data += Environment.NewLine + OneLine(exception.InnerException.Message + Environment.NewLine + exception.InnerException.StackTrace) + Environment.NewLine;
            }
            var fileReaderWriter = new FileReaderWriter();
            fileReaderWriter.WriteFile(LogFilePath, data);
        }
コード例 #3
0
ファイル: Logger.cs プロジェクト: yukseljunk/wps
 public static void LogProcess(string process)
 {
     if (String.IsNullOrEmpty(process)) return;
     var fileReaderWriter = new FileReaderWriter();
     fileReaderWriter.WriteFile(LogFilePath, OneLine(process));
 }