Ejemplo n.º 1
0
        /// <summary>
        /// log a specific event with a context message that requires some arguments to be created when requested.
        /// given arguments will be passed to the messageGetter so that it can create the context message without requiring lifted locals
        /// </summary>
        public static void Log <TArg>(FunctionId functionId, Func <TArg, string> messageGetter, TArg arg)
        {
            var logger = GetLogger();

            if (logger == null)
            {
                return;
            }

            if (!logger.IsEnabled(functionId))
            {
                return;
            }

            var logMessage = LogMessage.Create(messageGetter, arg);

            logger.Log(functionId, logMessage);
            logMessage.Free();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// log a specific event with a context message that requires some arguments to be created when requested.
        /// given arguments will be passed to the messageGetter so that it can create the context message without requiring lifted locals
        /// </summary>
        public static void Log <TArg0, TArg1, TArg2, TArg3>(FunctionId functionId, Func <TArg0, TArg1, TArg2, TArg3, string> messageGetter, TArg0 arg0, TArg1 arg1, TArg2 arg2, TArg3 arg3, LogLevel logLevel = LogLevel.Debug)
        {
            var logger = GetLogger();

            if (logger == null)
            {
                return;
            }

            if (!logger.IsEnabled(functionId))
            {
                return;
            }

            var logMessage = LogMessage.Create(messageGetter, arg0, arg1, arg2, arg3, logLevel);

            logger.Log(functionId, logMessage);
            logMessage.Free();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// log a specific event with a context message that will only be created when it is needed.
        /// the messageGetter should be cheap to create. in another word, it shouldn't capture any locals
        /// </summary>
        public static void Log(FunctionId functionId, Func <string> messageGetter, LogLevel logLevel = LogLevel.Debug)
        {
            var logger = GetLogger();

            if (logger == null)
            {
                return;
            }

            if (!logger.IsEnabled(functionId))
            {
                return;
            }

            var logMessage = LogMessage.Create(messageGetter, logLevel);

            logger.Log(functionId, logMessage);

            logMessage.Free();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// log a start and end pair with a context message that requires some arguments to be created when requested.
 /// given arguments will be passed to the messageGetter so that it can create the context message without requiring lifted locals
 /// </summary>
 public static IDisposable LogBlock <TArg0, TArg1, TArg2, TArg3>(FunctionId functionId, Func <TArg0, TArg1, TArg2, TArg3, string> messageGetter, TArg0 arg0, TArg1 arg1, TArg2 arg2, TArg3 arg3, CancellationToken token, LogLevel logLevel = LogLevel.Trace)
 => TryGetActiveLogger(functionId, out _) ?
 CreateLogBlock(functionId, LogMessage.Create(messageGetter, arg0, arg1, arg2, arg3, logLevel), GetNextUniqueBlockId(), token) :
 EmptyLogBlock.Instance;
Ejemplo n.º 5
0
 /// <summary>
 /// simplest way to log a start and end pair with a simple context message which should be very cheap to create
 /// </summary>
 public static IDisposable LogBlock(FunctionId functionId, string?message, CancellationToken token, LogLevel logLevel = LogLevel.Trace)
 => TryGetActiveLogger(functionId, out _) ?
 CreateLogBlock(functionId, LogMessage.Create(message ?? "", logLevel), GetNextUniqueBlockId(), token) :
 EmptyLogBlock.Instance;