Beispiel #1
0
        private void Log(object source, ILoggable loggable, LogLevel level)
        {
            var wrapper = new SplunkLogObject
            {
                Data        = loggable,
                LogContext  = RequestGuid,
                Source      = GetLoggingContext(source),
                Level       = level,
                Application = Assembly.GetEntryAssembly()?.GetName().Name,
                Machine     = Environment.MachineName,
                TimeStamp   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture),
                Event       = loggable.GetType().Name
            };

            sender.Send(Guid.NewGuid().ToString(), level.ToString(), null, wrapper, null);
        }
Beispiel #2
0
        ///<summary>Logs a single object to a file</summary>
        ///<exception cref="Exception">Thrown when failed to log data to file.</exception>
        public static void Log(ILoggable item, string path)
        {
            try
            {
                if (item != null)
                {
                    string logLine;

                    using (StreamWriter sw = new StreamWriter(path, true))
                    {
                        logLine = DateTime.Now.ToString() + ", " + item.GetType().ToString() + ", " + item.Log();
                        sw.WriteLine(logLine);
                    }
                }
            }
            catch (Exception)
            {
            }
        }
 internal static Logger GetLogger(ILoggable loggable)
 {
     return(new Logger(loggable.GetType()));
 }
 /// <summary>
 /// Builds the Log output of the form CLASSNAME: message. We assume that caller will never
 /// be null, which should be a safe bet.
 /// </summary>
 /// <returns>The message</returns>
 /// <param name="message">Message object, will be converted to string.</param>
 /// <param name="caller">Calling object whose type will be prepended to message.</param>
 public static string BuildOutput(object message, LogLevel logLevel, ILoggable caller = null)
 {
     return((_dateTimeEnabled ? GetDateTimeOutput() : "") + logLevel.ToString() + " " + (caller == null ?  "" : caller.GetType().ToString() + ": ") + (message == null ? "Null" : message.ToString()));
 }
 internal static Logger GetLogger(ILoggable loggable)
 {
     return new Logger(loggable.GetType());
 }
Beispiel #6
0
 public ChatovatkoException(ILoggable me, String message) : base()
 {
     stackTrace    = this.StackTrace;
     message       = message + "\n" + this.GetType().Name + "\n" + this.StackTrace;
     theLogMessage = new DefaultLoggerMessage(me.GetType().Name, message, me.GetLogSource(), DateTime.Now, true);
 }
Beispiel #7
0
 /// <summary>
 /// Extension of ILoggable. Is used to log "from" an object.
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="mask"></param>
 /// <param name="level"></param>
 /// <param name="format"></param>
 /// <param name="objs"></param>
 public static void Log(this ILoggable obj, DebugLevel mask, Verbosity level, string format, params object[] objs)
 {
     Log(mask, level, "[" + obj.GetType().Name + "]" + format, objs);
 }
Beispiel #8
0
 public static Logger GetLogger(ILoggable loggable, LoggingConfiguration config)
 {
     return GetLogger(loggable.GetType().Name, config);
 }