コード例 #1
0
//    public Func<LogLevel, EventId, object, Exception, SqlCommand> SqlCommandFormatter { get; set; }

        #region Public Methods

        public SqlLogger(ISqlBatchLogTask logger, ISqlLoggerSettings settings, string categoryName, Func <string, LogLevel, bool> filter = null)
        {
            _logger = logger;
            try
            {
                _settings = settings;

                if (_settings.ScopeSeparator == null)
                {
                    _settings.ScopeSeparator = "=>";
                }

                _categoryName = categoryName;
                if (filter == null)
                {
                    _filter = ((category, logLevel) => true);
                }
                else
                {
                    _filter = filter;
                }

                _ignoreLoggingErrors = settings.IgnoreLoggingErrors;
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }
コード例 #2
0
        public SqlBatchLogTask(ISqlLoggerSettings settings)
        {
            _settings = settings;
            BatchSize = Convert.ToInt32(_settings.BatchSize);

            InitColumnMapping();

            TableName = _settings.TableName;
        }
コード例 #3
0
        /// <summary>
        /// Adds Sql Logger to LoggerFactory
        /// </summary>
        /// <param name="loggerFactory">LoggerFactory Instance</param>
        /// <param name="settings">Sql Logger Settings</param>
        /// <param name="filter">If specified it will override all defined switches.</param>
        /// <returns></returns>
        public static ILoggerFactory AddSqlServerLogger(this ILoggerFactory loggerFactory,
                                                        ISqlLoggerSettings settings)
        {
            var logger = new SqlServerBatchLogTask(settings);

            loggerFactory.AddProvider(new SqlLogProvider(logger, settings));

            return(loggerFactory);
        }
コード例 #4
0
 public SqlLoggerTests()
 {
     _settings = Substitute.For <ISqlLoggerSettings>();
     _settings.LogLevel.Returns(LogLevel.Info);
     _settings.ConnectionString.Returns("Test");
     _settings.MessageFormat.Returns("{0}\t{1:yyyy-MM-dd_HH:mm}:\t{2}");
     _insertCommand = Substitute.For <IInsertLogRecordCommand>();
     _insertCommand.Insert(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(Task.CompletedTask);
     _logger = new Logger.SqlLogger(_settings, _insertCommand);
 }
コード例 #5
0
ファイル: SqlLogger.cs プロジェクト: AlivedDe/Logger
 public SqlLogger(ISqlLoggerSettings settings, IInsertLogRecordCommand insertCommand) : base(settings)
 {
     _settings      = settings;
     _insertCommand = insertCommand ?? throw new ArgumentNullException(nameof(insertCommand));
 }
コード例 #6
0
 /// <summary>
 /// Creates SQL Logger Provider
 /// </summary>
 /// <param name="settings">Logger Settings</param>
 /// <param name="filter">TODO..</param>
 public SqlLogProvider(ISqlBatchLogTask logger, ISqlLoggerSettings settings)
 {
     this._settings = settings;
     _logger        = logger;
 }
コード例 #7
0
        internal string[] GetScopeInformation(ISqlLoggerSettings settings)
        {
            if (settings.ScopeColumnMapping != null || settings.ScopeColumnMapping.Count > 0)
            {
                string[] dictionary;
                if (ScopeInformation == null)
                {
                    dictionary = new string[settings.ScopeColumnMapping.Count()];
                    var builder  = new StringBuilder();
                    var current  = this;
                    var scopeLog = string.Empty;
                    var length   = builder.Length;

                    //Is adding scope path configured
                    var addScopePath = !string.IsNullOrEmpty(settings.ScopeColumnMapping.FirstOrDefault(k => k.Key == "SCOPEPATH").Key);

                    while (current != null)
                    {
                        if (current.CurrentValue is IEnumerable <KeyValuePair <string, object> > )
                        {
                            foreach (var item in (IEnumerable <KeyValuePair <string, object> >)current.CurrentValue)
                            {
                                // TODO: For performance reasons we need to remove FirstOrDefault and additional IndexOf call and use only one call.
                                var map = settings.ScopeColumnMapping.FirstOrDefault(a => a.Key == item.Key);
                                if (!String.IsNullOrEmpty(map.Key))
                                {
                                    dictionary[settings.ScopeColumnMapping.IndexOf(map)] = item.Value.ToString();
                                }
                            }
                        }
                        if (addScopePath)
                        {
                            if (length == builder.Length)
                            {
                                scopeLog = $"{settings.ScopeSeparator}{current}";
                            }
                            else
                            {
                                scopeLog = $"{settings.ScopeSeparator}{current} ";
                            }

                            builder.Insert(length, scopeLog);
                        }
                        current = current.Parent;
                    }
                    if (addScopePath)
                    {
                        var map = settings.ScopeColumnMapping.FirstOrDefault(a => a.Key == "SCOPEPATH");
                        dictionary[settings.ScopeColumnMapping.IndexOf(map)] = builder.ToString();
                    }

                    this.ScopeInformation = dictionary.ToArray();
                }
                else
                {
                    dictionary = ScopeInformation;
                }
            }
            else
            {
                ScopeInformation = new string[settings.ScopeColumnMapping.Count()];
            }

            return(ScopeInformation);
        }
コード例 #8
0
 public SqlServerBatchLogTask(ISqlLoggerSettings settings) : base(settings)
 {
     _connectionString = settings.ConnectionString;
 }
コード例 #9
0
 public SqliteBatchLogTask(ISqlLoggerSettings settings) : base(settings)
 {
     _connectionString = settings.ConnectionString;
     _openFlags        = SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.Create;
 }