示例#1
0
        /// <summary>
        /// C#-oriented-method: Write a log line to the logger. Exposes all parameters in a way that should make
        /// it very easy to use the logging behaviour from C#.
        /// </summary>
        /// <remarks>
        /// This method takes the **LogLevel** first, and then the message; to avoid having to grapple with
        /// overload resolution. The other Log(string, LogLine ...) method is in F# and won't add the same
        /// good defaults as this method.
        /// </remarks>
        /// <param name="logger"></param>
        /// <param name="level"></param>
        /// <param name="message">This is the message that you want to log.
        /// It's worth noting that a message without string.Format-ed parameters, is more equal
        /// across time, and if you have custom data you want to pass, you should rather set
        /// that data on the 'data' property of LogLine (with SetData and SetDatas).</param>
        /// <param name="setterTransformer">
        /// There are extension methods in this library that go towards creating new instances
        /// of LogLine that you can use to change the value inside this function.
        /// </param>
        public static void Log(
            this Logger logger,
            LogLevel level,
            string message,
            Func <Message, Message> setterTransformer)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (level == null)
            {
                throw new ArgumentNullException("level");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (setterTransformer == null)
            {
                throw new ArgumentNullException("setterTransformer");
            }

            var line = MessageModule.CreateEvent(level, message);

            logger.log(setterTransformer(line));
        }
示例#2
0
        /// <summary>
        /// Log a verbose log message
        /// </summary>
        /// <param name="logger">logger to invoke the Log call on</param>
        /// <param name="message">Message to pass to the targets</param>
        /// <param name="e">The exception that occurred</param>
        public static void VerboseException(this Logger logger, string message, Exception e)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            logger.log(MessageModule.CreateEvent(LogLevel.Verbose, message).AddException(e));
        }
示例#3
0
        /// <summary>
        /// C#-oriented-method: Write a log line to the logger. Exposes all parameters in a way that should make
        /// it very easy to use the logging behaviour from C#.
        /// </summary>
        /// <remarks>
        /// This method takes the **LogLevel** first, and then the message; to avoid having to grapple with
        /// overload resolution. The other Log(string, LogLine ...) method is in F# and won't add the same
        /// good defaults as this method.
        /// </remarks>
        /// <param name="logger">Instance to invoke the extension method on</param>
        /// <param name="level"></param>
        /// <param name="message">A message to attach to the log line</param>
        /// <param name="data">Data to attach to the log line being sent to the target;
        /// e.g. if using LogStash, these properties will be fields. For performance
        /// improvements, you can send a dictionary, or otherwise you can
        /// send an anonymous object whose public properties are then serialised
        /// as a dictionary.
        /// This is the message that you want to log.
        /// It's worth noting that a message without string.Format-ed parameters, is more equal
        /// across time, and if you have custom data you want to pass, you should rather set
        /// that data on the 'data' property of LogLine (with SetData and SetDatas).
        /// </param>
        /// <param name="service"></param>
        /// <param name="timestamp">
        /// When the log entry was given; optional, defaults to when this method
        /// is called</param>
        public static void Log(
            this Logger logger,
            LogLevel level,
            string message,
            object data,
            string service    = null,
            Instant?timestamp = null)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (level == null)
            {
                throw new ArgumentNullException("level");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            var msg = MessageModule.CreateEvent(level, message);

            if (service != null)
            {
                msg.SetService(service);
            }
            if (data != null)
            {
                msg.AddData(data);
            }
            if (timestamp != null)
            {
                msg.SetTimestamp(timestamp.Value);
            }

            logger.log(msg);
        }