Ejemplo n.º 1
0
        public static void InitLoggers()
        {
            if (!Initialized)
            {
                LogManager.Enabled = true; // enable logger by default.

                if (WindowLogConfig.Instance.Enabled)
                {
                    LogTarget target = null;
                    switch (WindowLogConfig.Instance.Target.ToLower())
                    {
                    case "console":
                        target = new WindowTarget(WindowLogConfig.Instance.MinimumLevel, WindowLogConfig.Instance.MaximumLevel,
                                                  WindowLogConfig.Instance.IncludeTimeStamps);
                        break;

                    case "file":
                        target = new FileTarget(WindowLogConfig.Instance.FileName, WindowLogConfig.Instance.MinimumLevel,
                                                WindowLogConfig.Instance.MaximumLevel, WindowLogConfig.Instance.IncludeTimeStamps,
                                                WindowLogConfig.Instance.ResetOnStartup);
                        break;
                    }

                    if (target != null)
                    {
                        LogManager.AttachLogTarget(target);
                    }
                }

                if (PacketLogConfig.Instance.Enabled)
                {
                    LogTarget target = null;
                    switch (PacketLogConfig.Instance.Target.ToLower())
                    {
                    case "console":
                        target = new WindowTarget(PacketLogConfig.Instance.MinimumLevel, PacketLogConfig.Instance.MaximumLevel,
                                                  PacketLogConfig.Instance.IncludeTimeStamps);
                        break;

                    case "file":
                        target = new FileTarget(PacketLogConfig.Instance.FileName, PacketLogConfig.Instance.MinimumLevel,
                                                PacketLogConfig.Instance.MaximumLevel, PacketLogConfig.Instance.IncludeTimeStamps,
                                                PacketLogConfig.Instance.ResetOnStartup);
                        break;
                    }

                    if (target != null)
                    {
                        LogManager.AttachLogTarget(target);
                    }
                }

                if (ServerLogConfig.Instance.Enabled)
                {
                    LogTarget target = null;
                    switch (ServerLogConfig.Instance.Target.ToLower())
                    {
                    case "console":
                        target = new WindowTarget(ServerLogConfig.Instance.MinimumLevel, ServerLogConfig.Instance.MaximumLevel,
                                                  ServerLogConfig.Instance.IncludeTimeStamps);
                        break;

                    case "file":
                        target = new FileTarget(ServerLogConfig.Instance.FileName, ServerLogConfig.Instance.MinimumLevel,
                                                ServerLogConfig.Instance.MaximumLevel, ServerLogConfig.Instance.IncludeTimeStamps,
                                                ServerLogConfig.Instance.ResetOnStartup);
                        break;
                    }

                    if (target != null)
                    {
                        LogManager.AttachLogTarget(target);
                    }
                }

                _defaultLogger = new Logger("DefaultLogger");
                Initialized    = true;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Attachs a new log target.
 /// </summary>
 /// <param name="target"></param>
 public static void AttachLogTarget(LogTarget target)
 {
     LogTargets.Add(target);
 }