Exemple #1
0
        static public bool InitLog(string LogConf, string PrefileName)
        {
            try
            {
                LogConfig Conf = new LogConfig(0);
                Conf.PreFileName = PrefileName;

                if (LogConf.Length > 0)
                {
                    Conf.LoadInfoFromFile(LogConf);
                }

                Log.Init(Conf);
            }
            catch (Exception e)
            {
                Log.Error("InitLog", "Error : " + e.ToString());
                return(false);
            }

            Log.Notice("InitLog", "Logger initialized");
            return(true);
        }
Exemple #2
0
        public static bool InitLog(string LogConf, string LogsDir, string fileName)
        {
            try
            {
                LogConfig Conf = new LogConfig(0);
                Conf.FileName = fileName;
                Conf.LogFolder = LogsDir;

                if (LogConf.Length > 0)
                    Conf.LoadInfoFromFile(LogConf);

                Log.Init(Conf);
            }
            catch (Exception e)
            {
                Log.Error("InitLog", "Error : " + e.ToString());
                return false;
            }

            Log.Notice("InitLog", "Logger initialized");
            return true;
        }
Exemple #3
0
        public static void InitInstance(LogConfig Config)
        {
            try
            {
                if (Config == null)
                    Config = new LogConfig();

                if (!Config.LogFolder.StartsWith("/"))
                    Config.LogFolder = "/" + Config.LogFolder;

                string FileDir = Directory.GetCurrentDirectory() + Config.LogFolder;
                string BackDir = Directory.GetCurrentDirectory() + Config.LogFolder + "/Backup";

                try
                {
                    Directory.CreateDirectory(FileDir);
                    Directory.CreateDirectory(BackDir);
                }
                catch (Exception)
                {

                }

                FileDir += "/" + Config.FileName;
                BackDir += "/" + Config.FileName + "." + DateTime.Now.Hour + "h." + DateTime.Now.Minute + "m." + DateTime.Now.Second + "s";

                if (DumpFile == null)
                {
                    DumpFile = new FileInfo(FileDir);
                    if (DumpFile.Exists)
                        DumpFile.MoveTo(BackDir);

                    DumpFile = new FileInfo(FileDir);

                    if (FSDump != null)
                        FSDump.Close();

                    FSDump = DumpFile.Create();
                }

                if (Config != null)
                    _config = Config;

            }
            catch (Exception)
            {
                lock (Console.Out)
                    Console.WriteLine("Log : Log file already in use.");

                if (Config != null)
                    Config.Info.Dump = false;
            }
        }
Exemple #4
0
 public static void Init(LogConfig Config)
 {
     InitInstance(Config);
 }
Exemple #5
0
 static public void Init(LogConfig Config)
 {
     InitInstance(Config);
 }
Exemple #6
0
        static public void InitInstance(LogConfig Config)
        {
            try
            {
                if (Config == null)
                {
                    Config = new LogConfig();
                }

                if (!Config.LogFolder.StartsWith("/"))
                {
                    Config.LogFolder = "/" + Config.LogFolder;
                }

                string FileDir = Directory.GetCurrentDirectory() + Config.LogFolder;
                string BackDir = Directory.GetCurrentDirectory() + Config.LogFolder + "/Backup";

                try
                {
                    Directory.CreateDirectory(FileDir);
                    Directory.CreateDirectory(BackDir);
                }
                catch (Exception)
                {
                }

                FileDir += "/" + Config.FileName;
                BackDir += "/" + Config.FileName + "." + DateTime.Now.Hour + "h." + DateTime.Now.Minute + "m." + DateTime.Now.Second + "s";

                if (DumpFile == null)
                {
                    DumpFile = new FileInfo(FileDir);
                    if (DumpFile.Exists)
                    {
                        DumpFile.MoveTo(BackDir);
                    }

                    DumpFile = new FileInfo(FileDir);

                    if (FSDump != null)
                    {
                        FSDump.Close();
                    }

                    FSDump = DumpFile.Create();
                }

                if (Config != null)
                {
                    _config = Config;
                }
            }
            catch (Exception)
            {
                lock (Console.Out)
                    Console.WriteLine("Log : Log file already in use.");

                if (Config != null)
                {
                    Config.Info.Dump = false;
                }
            }
        }