Exemple #1
0
 public void Message(object sender, LogEvent.Severity severity, string msg)
 {
     if (OnMessage != null)
     {
         OnMessage(sender, new LogEvent(severity, msg));
     }
 }
Exemple #2
0
        private string FormatMsg(LogEvent.Severity severity, string msg, params object[] args)
        {
            if (Format != null)
            {
                var stackTrace = new StackTrace();

                msg = _formatRegEx.Replace(Format, m => {
                    switch (m.Groups[1].Value)
                    {
                    case "%": return("%");

                    case "s": return(severity.ToString().ToLower());

                    case "S": return(severity.ToString().ToUpper());

                    case "m": return(msg);

                    case "c":
                        var frame  = stackTrace.GetFrame(2);
                        var method = frame.GetMethod();
                        var type   = method.ReflectedType;

                        return(type.Namespace + "." + type.Name + "." + method.Name);    // + ":" + frame.GetFileLineNumber();
                    }

                    return(m.Value);
                });
            }

            return(String.Format(msg, args));
        }
Exemple #3
0
        public static void OnLogEventOccurred(string message, LogEvent.Severity severity)
        {
            EventHandler <EventArgs <LogEvent> > handler = LogEvent;

            if (handler != null)
            {
                handler(
                    null,
                    new EventArgs <LogEvent>(
                        new LogEvent()
                {
                    LogSeverity = severity,
                    Message     = message,
                    Timestamp   = DateTime.Now,
                }));
            }
        }