Ejemplo n.º 1
0
        /// <summary>
        /// Logs a message to the given log target and also displays a print statement.
        /// </summary>
        /// <param name="message">The message to log. Can include newline (\n) characters to split into multiple lines.</param>
        /// <param name="target">The logging target (file).</param>
        /// <param name="level">The verbosity level.</param>
        public static void LogPrint(string message, LoggingTarget target = LoggingTarget.Runtime, LogLevel level = LogLevel.Verbose)
        {
#if DEBUG
            System.Diagnostics.Debug.Print(message);
#endif
            Log(message, target, level);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Log an arbitrary string to a specific log target.
 /// </summary>
 /// <param name="message">The message to log. Can include newline (\n) characters to split into multiple lines.</param>
 /// <param name="target">The logging target (file).</param>
 /// <param name="level">The verbosity level.</param>
 public static void Log(string message, LoggingTarget target = LoggingTarget.Runtime, LogLevel level = LogLevel.Verbose)
 {
     try
     {
         GetLogger(target, true).Add(message, level);
     }
     catch { }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// For classes that regularly log to the same target, this method may be preferred over the static Log method.
        /// </summary>
        /// <param name="target">The logging target.</param>
        /// <returns></returns>
        public static Logger GetLogger(LoggingTarget target = LoggingTarget.Runtime)
        {
            Logger l;

            if (!static_loggers.TryGetValue(target, out l))
            {
                static_loggers[target] = l = new Logger(target);
                l.Clear();
            }

            return(l);
        }
Ejemplo n.º 4
0
        public static void Error(Exception e, string description, LoggingTarget target = LoggingTarget.Runtime, bool recursive = false)
        {
            Log($@"ERROR: {description}", target, LogLevel.Error);
            Log(e.ToString(), target, LogLevel.Error);

            if (recursive)
            {
                for (Exception inner = e.InnerException; inner != null; inner = inner.InnerException)
                {
                    Log(inner.ToString(), target, LogLevel.Error);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// For classes that regularly log to the same target, this method may be preferred over the static Log method.
        /// </summary>
        /// <param name="target">The logging target.</param>
        /// <param name="clearOnConstruct">Decides whether we clear any existing content from the log the first time we construct this logger.</param>
        /// <returns></returns>
        public static Logger GetLogger(LoggingTarget target = LoggingTarget.Runtime, bool clearOnConstruct = false)
        {
            Logger l;

            if (!staticLoggers.TryGetValue(target, out l))
            {
                staticLoggers[target] = l = new Logger(target);
                if (clearOnConstruct)
                {
                    l.Clear();
                }
            }

            return(l);
        }
Ejemplo n.º 6
0
        public static void AddLoggingTarget(LoggingTarget.LoggingTarget loggingTarget)
        {
            var appender = (AppenderSkeleton) loggingTarget.Appender;

            var layout = new PatternLayout {ConversionPattern = "[%date] [%thread] %-5level %logger - %message%newline"};
            layout.ActivateOptions();

            appender.Layout = layout;
            appender.ActivateOptions();
            BasicConfigurator.Configure(appender);

            Type appenderType = loggingTarget.Appender.GetType();

            if (!AppendersTypes.Contains(appenderType))
            {
                AppendersTypes.Add(appenderType);
                Logger.Parent.AddAppender(appender);
            }
        }
Ejemplo n.º 7
0
        public bool LogMessage(string message, LoggingTarget target)
        {
            ILogger Logger = null;

            switch (target)
            {
            case LoggingTarget.Console:
                Logger = new WindowsLogger();
                break;

            case LoggingTarget.Database:
                //Logger = new DatabaseLogger();
                break;
            }

            if (Logger != null)
            {
                return(Logger.LogMessage(message));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// For classes that regularly log to the same target, this method may be preferred over the static Log method.
 /// </summary>
 /// <param name="target">The logging target.</param>
 /// <returns>The logger responsible for the given logging target.</returns>
 public static Logger GetLogger(LoggingTarget target = LoggingTarget.Runtime)
 {
     // there can be no name conflicts between LoggingTarget-based Loggers and named loggers because
     // every name that would coincide with a LoggingTarget-value is reserved and cannot be used (see ctor).
     return(GetLogger(target.ToString()));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Log an arbitrary string to the specified logging target.
 /// </summary>
 /// <param name="message">The message to log. Can include newline (\n) characters to split into multiple lines.</param>
 /// <param name="target">The logging target (file).</param>
 /// <param name="level">The verbosity level.</param>
 public static void Log(string message, LoggingTarget target = LoggingTarget.Runtime, LogLevel level = LogLevel.Verbose)
 {
     log(message, target, null, level);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Logs the given exception with the given description to the specified logging target.
 /// </summary>
 /// <param name="e">The exception that should be logged.</param>
 /// <param name="description">The description of the error that should be logged with the exception.</param>
 /// <param name="target">The logging target (file).</param>
 /// <param name="recursive">Whether the inner exceptions of the given exception <paramref name="e"/> should be logged recursively.</param>
 public static void Error(Exception e, string description, LoggingTarget target = LoggingTarget.Runtime, bool recursive = false)
 {
     error(e, description, target, null, recursive);
 }
 public void ShouldBeAbleToUsePredicateExtensionMethod()
 {
     LoggingTarget.ShouldHaveLogged(x => x == _message);
 }
Ejemplo n.º 12
0
        public static void RemoveLoggingTarget(LoggingTarget.LoggingTarget loggingTarget)
        {
            Type appenderType = loggingTarget.Appender.GetType();

            AppendersTypes.Remove(appenderType);
            Logger.Parent.Appenders.ToArray().ToList().RemoveAll(item => item.GetType() == appenderType);
        }
Ejemplo n.º 13
0
 public void Log(string Message, LoggingTarget Target = LoggingTarget.Runtime, LogLevel LogLevel = LogLevel.Verbose)
 => Logger.Log(Message, Target, LogLevel);
 public void ShouldBeAbleToUseStringExtensionMethod()
 {
     LoggingTarget.ShouldHaveLogged(_message);
 }
Ejemplo n.º 15
0
 private Logger(LoggingTarget target = LoggingTarget.Runtime)
 {
     Target = target;
 }
Ejemplo n.º 16
0
 public static void Error(Exception e, string description, LoggingTarget target = LoggingTarget.Runtime)
 {
     Log($@"ERROR: {description}", target, LogLevel.Error);
     Log(e.ToString(), target, LogLevel.Error);
 }
Ejemplo n.º 17
0
 private void ClearLogs()
 {
     LoggingTarget.Clear();
 }