public void AddLog(HttpRequest httpRequest, IHttpContextAccessor _httpContextAccessor, string Controller = "", string Action = "", string Comment = "") { try { var RemoteIp = GetRemoteIpAddress(httpRequest); var RemotePort = GetRemotePort(httpRequest); var LocalIp = GetLocalIPAddress(httpRequest); var LocalPort = GetLocalPort(httpRequest); var log = new Log { Controller = Controller, Action = Action, RemoteIpAddress = RemoteIp, RemotePort = RemotePort, LocalIpaddress = LocalIp, LocalPort = LocalPort, Comment = Comment, Date = DateTime.Now }; _logRepository.Add(log); } catch (Exception) { var error = new Log { Controller = "LogService", Action = "AddLog", Comment = "Error" }; _logRepository.Add(error); } }
/// <summary> /// Returns a collection of all the purchases entities /// in the database. /// </summary> /// <returns>An IEnumerable collection of PurchaseModel entity instances.</returns> public IEnumerable <PurchaseModel> GetAll() { try { using (Context context = new Context()) { return(context.Purchases.ToList()); } } catch (Exception e) { logsRepository.Add(e.Message); } return(null); }
/// <summary> /// Adds an abstract book to the database. /// </summary> /// <param name="abstarctBook">The AbstractBookModel entity instance to add.</param> /// <returns>A fully populated AbstarctBookModel entity instance.</returns> public AbstractBookModel Add(AbstractBookModel abstractBook) { try { using (Context context = new Context()) { context.AbstractBooks.Add(abstractBook); context.SaveChanges(); return(abstractBook); } } catch (Exception e) { logsRepository.Add(e.Message); } return(null); }
/// <summary> /// Create a log instance out of the message. /// </summary> public override void Log(string message) { try { _logsRepository.Add(CreateLog(message)); } catch { //if db connection is the error it cant be logged to db } }
public void Log(string endpoint, string message, int?userId = null) { var log = new Log() { DateCreated = DateTime.Now, Endpoint = endpoint, Message = message, UserId = userId }; logsRepository.Add(log); }