コード例 #1
0
        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);
            }
        }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
 /// <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
     }
 }
コード例 #5
0
        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);
        }