Beispiel #1
0
		/// <summary>
		/// Reads the log data.
		/// </summary>
		/// <param name="from">Initial timestamp to search from.</param>
		/// <param name="to">Final timestamp up search to.</param>
		/// <returns>Collection of log items found</returns>
		public IReadOnlyCollection<LogItem> ReadLogData(DateTimeOffset @from, DateTimeOffset to)
		{
			var list = new List<LogItem>();
			var task = factory.OpenConnection();
			task.Wait();
			using (var connection = task.Result)
			{
				var cmd = connection.CreateCommand();
				cmd.CommandText = "SELECT cast(Timestamp as datetime), Severity, Message FROM Log WHERE Timestamp >= @from AND Timestamp <= @to ORDER BY Timestamp DESC";

				var paramFrom = cmd.CreateParameter();
				paramFrom.ParameterName = "@from";
				paramFrom.Value = @from;
				cmd.Parameters.Add(paramFrom);

				var paramTo = cmd.CreateParameter();
				paramTo.ParameterName = "@to";
				paramTo.Value = to;
				cmd.Parameters.Add(paramTo);

				using (var reader = cmd.ExecuteReader())
				{
					while (reader.Read())
					{
						var timestamp = reader.GetDateTime(0);
						LogSeverity severity;
						Enum.TryParse(reader.GetString(1), out severity);
						var message = reader.GetString(2);
						var item = new LogItem(timestamp, severity, message);
						list.Add(item);
					}
				}
				return list;
			}
		}
Beispiel #2
0
			public LogItemModel(LogItem logItem)
			{
				RequiresNotNull(logItem);
				LogItem = logItem;
			}