コード例 #1
0
        /// <summary>
        /// Log Error
        /// </summary>
        /// <param name="onlyIfUnique">Only is is unique</param>
        public void Save(bool onlyIfUnique)
        {
            if (ReplicationData == null || ReplicationData.Length <= 0)
            {
                return;
            }

            var step = Error == EFuzzingErrorType.Crash ? "crashes" : "failures";
            var name = $"{step}/{DateTime.UtcNow.ToString("yyyy-MM-dd")}/uniques/{ErrorId.ToString()}.zip";

            if (!File.Exists(name))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(name));
                File.WriteAllBytes(name, ReplicationData);
            }

            if (onlyIfUnique)
            {
                return;
            }

            name = $"{step}/{DateTime.UtcNow.ToString("yyyy-MM-dd")}/{Guid.NewGuid().ToString()}.zip";
            Directory.CreateDirectory(Path.GetDirectoryName(name));
            File.WriteAllBytes(name, ReplicationData);
        }
コード例 #2
0
        //TODO prepare some kind of my own errors with to log file mmethods - use Application_Error() method for that

        /// <summary>
        /// Some sort of try to catch all errors that wasnt cought
        /// </summary>
        /// <param name="e">Exception that was made and i hope it will work</param>
        protected void Application_Error()
        {
            Exception e = Server.GetLastError();
            string    PathToErrorFile = KneaderPrototype.Error.PathToErrorFile;
            DateTime  now             = DateTime.Now;

            ErrorId++;
            string timestamp = "\r\n" + now.ToString();

            if (PathToErrorFile != null)
            {
                System.IO.File.AppendAllText(PathToErrorFile, timestamp);
                System.IO.File.AppendAllText(PathToErrorFile, ErrorId.ToString());                                                             //set id  of Error
                System.IO.File.AppendAllText(PathToErrorFile, e.Message.ToString());
                System.IO.File.AppendAllText(PathToErrorFile, e.StackTrace.ToString());                                                        //Write Error to file
                Session["tempforview"] = timestamp + "    Error Id:" + ErrorId.ToString() + " occured so please try it again after some time"; //To screen also with id
            }
            else
            {
                if (Directory.Exists(Path.PhysicalPath + @"\ErroLog") == true &&
                    Directory.GetDirectories(Path.PhysicalPath, e.Source.ToString()) != null)
                {
                    PathToErrorFile = Path.PhysicalPath + @"\ErrorLog\" + e.Source.ToString() + @"\log.txt";
                    if (!System.IO.File.Exists(PathToErrorFile))
                    {
                        System.IO.File.Create(PathToErrorFile).Close(); //If log.txt does not exist create one
                    }
                    System.IO.File.AppendAllText(PathToErrorFile, timestamp);
                    System.IO.File.AppendAllText(PathToErrorFile, ErrorId.ToString());                                                             //set id  of Error
                    System.IO.File.AppendAllText(PathToErrorFile, e.Message.ToString());                                                           //Write Error to file
                    System.IO.File.AppendAllText(PathToErrorFile, e.StackTrace.ToString());                                                        //Write Error to file
                    Session["tempforview"] = timestamp + "    Error Id:" + ErrorId.ToString() + " occured so please try it again after some time"; //To screen also with id
                }
                else
                {
                    Directory.CreateDirectory(Path.PhysicalPath + @"\ErrorLog\" + e.Source.ToString());      //If directory in the path does not exist create one
                    PathToErrorFile = Path.PhysicalPath + @"\ErrorLog\" + e.Source.ToString() + @"\log.txt"; //Asign path to Path attribute
                    if (!System.IO.File.Exists(PathToErrorFile))
                    {
                        System.IO.File.Create(PathToErrorFile).Close(); //If log.txt does not exist create one
                    }
                    System.IO.File.AppendAllText(PathToErrorFile, timestamp);
                    System.IO.File.AppendAllText(PathToErrorFile, ErrorId.ToString());                                                             //set id  of Error
                    System.IO.File.AppendAllText(PathToErrorFile, e.Message.ToString());                                                           //Write Error to file
                    System.IO.File.AppendAllText(PathToErrorFile, e.StackTrace.ToString());                                                        //Write Error to file
                    Session["tempforview"] = timestamp + "    Error Id:" + ErrorId.ToString() + " occured so please try it again after some time"; //To screen also with id
                }
            }
            Server.ClearError();
        }