コード例 #1
0
ファイル: FireLogger.cs プロジェクト: ah01/NFireLogger
        /// <summary>
        /// Add new message to output with info from stacktrace (source file name and line of caller)
        /// </summary>
        /// <param name="stackTraceOffset">Offset of caller in stacktrace (to skip record from FireLogger)</param>
        /// <param name="name">Logger name</param>
        /// <param name="level">Log level</param>
        /// <param name="text">Text of message</param>
        /// <param name="parameters">Parameters of message</param>
        internal void Log(int stackTraceOffset, string name, Level level, string text, params object[] parameters)
        {
            if (!InternalEnabled) return;

            var msg = new LogMessage
                          {
                              Level     = level,
                              Message   = text,
                              Arguments = parameters,
                              Name      = name
                          };

            PopulateStackInfo(msg, stackTraceOffset + 1);

            Log(msg);
        }
コード例 #2
0
ファイル: FireLogger.cs プロジェクト: ah01/NFireLogger
        /// <summary>
        /// Add info about source file name and line from stacktrace
        /// </summary>
        /// <param name="msg">Log Message</param>
        /// <param name="stackTraceOffset">Offset of caller in stacktrace (to skip record from FireLogger)</param>
        private void PopulateStackInfo(LogMessage msg, int stackTraceOffset)
        {
            if (stackTraceOffset < 0) return;

            if (!LogFileInfo) return;

            var frame = new StackFrame(stackTraceOffset + 1, true);

            // NOTE when PDB files are missing (e.g. production servers) result values is null, consider some info values
            // TODO do something with path (it's absolute)

            msg.PathName = frame.GetFileName();
            msg.LineNo   = frame.GetFileLineNumber();
        }
コード例 #3
0
ファイル: FireLogger.cs プロジェクト: ah01/NFireLogger
 /// <summary>
 /// Add new message to output
 /// </summary>
 /// <param name="message"></param>
 public virtual void Log(LogMessage message)
 {
     if (InternalEnabled && message != null)
     {
         lock (this)
         {
             Logs.Add(message);
         }
     }
 }