コード例 #1
0
        public async Task <LogSearchResults> FilterLogsAsync(LogSearchCriteria searchCriteria)
        {
            var hash = GetApplicationHash(searchCriteria.ApplicationPath);

            if (!LogTable.IsLogTableAvailable(AppLogTablePrefix + hash))
            {
                return(new LogSearchResults {
                    FoundItems = new LogRecord[0]
                });
            }

            if (string.IsNullOrEmpty(searchCriteria.ApplicationPath))
            {
                throw new ArgumentException("ApplicationPath is required to filter the logs");
            }
            var whereSql   = PrepareWhereSectionOfTheQuery(searchCriteria);
            var orderBySql = string.Format("order by TimeUtc desc limit {0},{1}", searchCriteria.Offset, searchCriteria.Limit);

            using (var conn = new MySqlConnection(MySqlLogStoreConfiguration.ConnectionString)) {
                await conn.OpenAsync();

                var dbapplogs = (await conn.QueryAsync <DbAppLogRecord>(string.Format("select * from {0}{1} {2} {3}", AppLogTablePrefix, hash, whereSql, orderBySql), new {
                    searchCriteria.FromUtc,
                    searchCriteria.ToUtc,
                    searchCriteria.Server,
                    Logger = searchCriteria.Logger + "%",
                    searchCriteria.Levels,
                    HttpStatusCode = searchCriteria.Keywords.HttpStatus + "%",
                    Url = searchCriteria.Keywords.Url + "%",
                    ClientIp = searchCriteria.Keywords.ClientIp + "%",
                    ServiceName = searchCriteria.Keywords.Service + "%"
                })).ToArray();

                return(new LogSearchResults {
                    FoundItems = ConvertDbLogRecordToPublicModel(dbapplogs)
                });
            }
        }
コード例 #2
0
 internal MySqlLogStore(Func <DateTime> currentUtcDateRetriever)
 {
     logTable = new LogTable(currentUtcDateRetriever);
 }