Exemplo n.º 1
0
        public static void Initialize(LogType logLevel, LogWriter fileLogger = null)
        {
            Console.OutputEncoding = Encoding.UTF8;

            Log.logLevel = logLevel;

            var logThread = new Thread(() =>
            {
                while (true)
                {
                    var log = logQueue.Take();

                    if (log != null && log.Item2 != null)
                    {
                        if (fileLogger != null)
                            Task.Run(async () => await fileLogger.Write(log.Item2));

                        Console.ForegroundColor = log.Item1;
                        Console.WriteLine(log.Item2);
                    }
                }
            });

            logThread.IsBackground = true;
            logThread.Start();
        }
Exemplo n.º 2
0
        public static void Initialize(string file)
        {
            config = new Config(file);

            if (config != null)
            {
                IsInitialized = true;

                LogLevel       = (LogType)config.Read("Log.Level", 0x7, true);
                LogDirectory   = config.Read("Log.Directory", "Logs/World");
                LogConsoleFile = config.Read("Log.Console.File", "");
                LogPacketFile  = config.Read("Log.Packet.File", "");

                LogWriter fl = null;

                if (LogConsoleFile != "")
                {
                    if (!Directory.Exists(LogDirectory))
                        Directory.CreateDirectory(LogDirectory);

                    fl = new LogWriter(LogDirectory, LogConsoleFile);
                }

                Log.Initialize(LogLevel, fl);

                if (LogPacketFile != "")
                    PacketLog.Initialize(LogDirectory, LogPacketFile);
            }

            ReadConfig();
        }
Exemplo n.º 3
0
        public static void Initialize(string file)
        {
            config = new Config(file);

            if (config != null)
            {
                LogDirectory   = config.Read("Log.Directory", "Logs/StsServer");
                LogConsoleFile = config.Read("Log.Console.File", "");
                LogPacketFile  = config.Read("Log.Packet.File", "");

                LogWriter fl = null;

                if (LogConsoleFile != "")
                {
                    if (!Directory.Exists(LogDirectory))
                        Directory.CreateDirectory(LogDirectory);

                    fl = new LogWriter(LogDirectory, LogConsoleFile);
                }

                if (LogPacketFile != "")
                    PacketLog.Initialize(LogDirectory, LogPacketFile);
            }

            ReadConfig();
        }
Exemplo n.º 4
0
        public static async void Write(Exception ex)
        {
            if (!initialized)
            {
                // Initialize exception logger
                if (!Directory.Exists("Crashes"))
                    Directory.CreateDirectory("Crashes");

                var el = new LogWriter("Crashes", "Crash.log");

                await Initialize(el);

                initialized = true;
            }

            var sb = new StringBuilder();

            sb.Append($"Time: [{DateTime.Now}]");
            sb.AppendLine();

            sb.Append($"Message: {ex.Message}");
            sb.AppendLine();

            sb.Append($"StackTrace: {ex.StackTrace}");
            sb.AppendLine();
            sb.AppendLine();

            logQueue.Add(sb.ToString());
        }
Exemplo n.º 5
0
        static async Task Initialize(LogWriter fileLogger = null)
        {
            await Task.Delay(1).ContinueWith(async _ =>
            {
                while (true)
                {
                    var log = logQueue.Take();

                    if (log != null && fileLogger != null)
                        await fileLogger.Write(log);
                }
            });
        }
Exemplo n.º 6
0
        public static void Initialize(string file)
        {
            // Initialize exception logger
            if (!Directory.Exists("Crashes"))
                Directory.CreateDirectory("Crashes");

            var el = new LogWriter("Crashes", "RemoteServer.log");

            ExceptionLog.Initialize(el);

            // Initialize unhandled exception handler/logger
            AppDomain.CurrentDomain.UnhandledException += (o, e) =>
            {
                var ex = (Exception)e.ExceptionObject;

                ExceptionLog.Write(ex);
            };

            config = new Config(file);

            if (config != null)
            {
                IsInitialized = true;

                LogLevel       = (LogType)config.Read("Log.Level", 0x7, true);
                LogDirectory   = config.Read("Log.Directory", "Logs/Remote");
                LogConsoleFile = config.Read("Log.Console.File", "");
                LogPacketFile  = config.Read("Log.Packet.File", "");

                LogWriter fl = null;

                if (LogConsoleFile != "")
                {
                    if (!Directory.Exists(LogDirectory))
                        Directory.CreateDirectory(LogDirectory);

                    fl = new LogWriter(LogDirectory, LogConsoleFile);
                }

                Log.Initialize(LogLevel, fl);

                if (LogPacketFile != "")
                    PacketLog.Initialize(LogDirectory, LogPacketFile);
            }

            ReadConfig();
        }
Exemplo n.º 7
0
        public static async void Initialize(LogType logLevel, LogWriter fileLogger = null)
        {
            Log.logLevel = logLevel;

            await Task.Delay(1).ContinueWith(async _ =>
            {
                while (true)
                {
                    var log = logQueue.Take();

                    if (log != null)
                    {
                        var msg = log.Item2;

                        if (fileLogger != null)
                            await fileLogger.Write(msg);

                        Console.ForegroundColor = log.Item1;
                        Console.WriteLine(msg);
                    }
                }
            });
        }