示例#1
0
        /// <summary>
        /// Logs a new message and calls all loggers in this factory to inform them of the new log
        /// </summary>
        /// <param name="message">The message to log</param>
        /// <param name="level">The level of severity for this log message. The default is Information</param>
        /// <param name="origin">The origin of this log message. Useful for tracing. The default is the method name of the caller</param>
        /// <example>
        /// From inside MyFunction() => Logger.Log("Some message")
        /// returns: "Some message --MyFunction()"
        /// </example>
        public void Log(string message, LogFactoryLevel level = LogFactoryLevel.Information, [CallerMemberName] string origin = "")
        {
            // Add method name if specified
            if (this.LogMethodName)
            {
                message = string.Format(this.LogMethodNameFormat, message, origin);
            }

            // Send message to all loggers
            mLoggers.ForEach(f => f.Log(level, message));

            SafeWait(() =>
            {
                // Add to list
                mLogHistory.Add(new LogDetails {
                    Date = DateTime.UtcNow, Level = level, Message = message
                });

                // Prune list
                if (mLogHistory.Count > 200)
                {
                    mLogHistory.RemoveAt(0);
                }
            });

            // Inform listeners
            if (NewLog != null)
            {
                NewLog(message, level);
            }
        }
示例#2
0
 /// <summary>
 /// Log a message to the injected ILogFactory class that the application is using, if any is used
 /// </summary>
 /// <param name="message">The message to log</param>
 /// <param name="level">The level of severity of this log message</param>
 /// <param name="memberName">The name of the calling method. The default is the calling method's name.</param>
 /// <param name="filePath">The file path to the calling method. The default is the callers method file path</param>
 /// <param name="lineNumber">The line number in source code of the caller method. The default is the caller methods line number</param>
 public static void Log(string message, LogFactoryLevel level = LogFactoryLevel.Information,
                        [CallerMemberName] string memberName  = "",
                        [CallerFilePath] string filePath      = "",
                        [CallerLineNumber] int lineNumber     = 0)
 {
     IoCContainer.Get <ILogFactory>().Log(message, level, $"[{FileHelpers.GetFileFolderName(filePath)} line {lineNumber} {memberName}()]");
 }
示例#3
0
        public void Log(LogFactoryLevel level, string message)
        {
            var output = $"[{level}] {message}";

            Trace.WriteLine(output);
        }