コード例 #1
0
ファイル: LogContext.cs プロジェクト: hoserdude/buche-dot-net
        /// <summary>
        /// Capture all log context values from logger and return a new LogContext object.
        /// </summary>
        internal static LogContext Get(ILogger logger)
        {
            var properties = new Dictionary<string, string>();

            foreach (var propertyKeyField in PropertyKey.Fields)
            {
                var propertyKey = propertyKeyField.GetValue(DummyLogContext) as string;
                var propertyValue = logger.GetProperty(propertyKey);
                if (propertyKey != null && properties.ContainsKey(propertyKey)) properties[propertyKey] = propertyValue;
            }

            return new LogContext(properties);
        }
コード例 #2
0
        public LogOperation(ILogger logger, string value)
        {
            Logger = logger;
            PreviousValue = Logger.GetProperty(LogContext.PropertyKey.Operation);

            // set the new key/value
            if (PreviousValue.HasValue())
            {
                Logger.SetProperty(LogContext.PropertyKey.Operation, PreviousValue + "." + value);
            }
            else
            {
                Logger.SetProperty(LogContext.PropertyKey.Operation, value);
            }
        }