Пример #1
0
        public static bool Write(string log, string file, string section, int type)
        {
            try
            {
                if (!Directory.Exists(Configuration.Root + Path.DirectorySeparatorChar + file))
                {
                    Directory.CreateDirectory(Configuration.Root + Path.DirectorySeparatorChar + file);
                }

                // format the name of file
                switch (type)
                {
                case 3:
                case 1:
                case 5:
                    section = section + "_" + DateTime.Now.ToString("yyyy_MM_dd");
                    break;
                }

                string suffix = ".txt";

                switch (type)
                {
                case 2:
                case 3:
                    suffix = ".html";
                    break;

                case 4:
                case 5:
                    suffix = ".xml";
                    break;
                }

                string name = Configuration.Root +
                              Path.DirectorySeparatorChar + file + Path.DirectorySeparatorChar +
                              file + "_" + section + suffix;
                if (section == "" || section == null)
                {
                    name = Configuration.Root +
                           Path.DirectorySeparatorChar + file + Path.DirectorySeparatorChar +
                           file + suffix;
                }

                string data = DateTime.Now.ToString() + ": " + log;
                // format text

                switch (type)
                {
                case 2:
                case 3:
                    data = "<font class=\"timestamp\">" + DateTime.Now.ToString() +
                           "</font><font class=\"text\">: " + System.Web.HttpUtility.HtmlEncode(log) + "</font><br>";
                    break;

                case 4:
                case 5:
                    data = "<data time=\"" + Unix() + "\">" + System.Web.HttpUtility.HtmlEncode(log) + "</data>";
                    break;
                }

                Writer.InsertText(data, name);
                return(true);
            } catch (Exception fail)
            {
                MainClass.exceptionHandler(fail);
            }
            return(false);
        }