Esempio n. 1
0
 public void LogError(Type t, string Message, Exception e)
 {
     using (context)
     {
         context.Add(new LogEntry()
         {
             LogTime      = DateTime.Now,
             ErrorType    = "Error",
             ErrorMessage = Message,
             Location     = t.FullName,
             StackTrace   = e.StackTrace
         });
         context.SaveChanges();
     }
 }
Esempio n. 2
0
 public void Create(string endpoint, string data)
 {
     _context.Add(new Log {
         CreatedAt = DateTime.Now, Endpoint = endpoint, Data = data
     });
     _context.SaveChanges();
 }
Esempio n. 3
0
 public void Archive(string endpoint, string data)
 {
     context.Add(new Log {
         Endpoint  = endpoint,
         Data      = data,
         CreatedAt = DateTime.Now
     });
     context.SaveChanges();
 }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id,Author,LoggedDate,LogLevel,Message,Reference,Type")] Log log)
        {
            if (ModelState.IsValid)
            {
                _context.Add(log);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(log));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("LogId,TradingPartnerCode,RecordYear,RecordMonth,GrievanceTotal,GrievanceSubmits,GrievanceErrors,AppealTotal,AppealSubmits,AppealErrors,COCTotal,COCSubmits,COCErrors,OONTotal,OONSubmits,OONErrors,PCPATotal,PCPASubmits,PCPAErrors,RunStatus,RunTime,RunBy")] ProcessLog processLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(processLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(processLog));
        }
Esempio n. 6
0
 private void InsertRecords(List <Dictionary <string, string> > data) // async Task  Async
 {
     foreach (var row in data)
     {
         _context.Add(new InConnectionLog
         {
             name  = row["packID:name"].Split(_config.GetSection("splitColsVals").Value)[1],
             srcIp = $"{row["ipFrom"]}:{row["portFrom"]}",
             dstIp = $"{row["ipTo"]}:{row["portTo"]}",
             dTime = DateTime.ParseExact($"{row["date"]} {row["time"]}", "MMM d yyyy h:m:s", null),
             logId = int.Parse(row["logId"])
         });
     }
     _context.SaveChanges(); // await Async
 }
Esempio n. 7
0
        private async Task MakeLogAsync(ModLog modLog, string reason = null)
        {
            // Get our logging channel.
            var logChannel = Context.Guild.TextChannels.FirstOrDefault(channel => channel.Name.ToLower() == _config["moderation_log_channel"].ToLower());

            // Define our embed color based on log severity.
            Color embedColour;

            switch (modLog.Severity)
            {
            case (Severity.Severe):
                embedColour = Color.Red;
                break;

            case (Severity.Medium):
                embedColour = Color.DarkOrange;
                break;

            default:
                embedColour = Color.Orange;
                break;
            }

            // add our log and save changes
            _dctx.Add(modLog);
            await _dctx.SaveChangesAsync();

            // grab the entry so we can get the id
            var dbLog = _dctx.Modlogs.LastOrDefault();
            // build our embed
            var logEmbed = new EmbedBuilder
            {
                Title       = $"Log Message",
                Description = dbLog.Action + "\n\n" +
                              $"Time: {dbLog.Time.ToString("HH:mm:ss dd/MM/yyy")} GMT+0\n\n" +
                              $"Reason: {reason ?? _config["prefix"] + $"reason {dbLog.Id} to set a reason."}",
                Color  = embedColour,
                Footer = (new EmbedFooterBuilder {
                    Text = $"Case {dbLog.Id}"
                })
            };
            // send it off.
            var message = await logChannel.SendMessageAsync("", false, logEmbed.Build());

            // update the modlog with the id of the message that it refers to, so we can use the reason command later on.
            dbLog.MessageId = message.Id;
            await _dctx.SaveChangesAsync();
        }
Esempio n. 8
0
 public void Post([FromBody] log value)
 {
     if ((value.log_type == "exception" || value.log_type == "trace" || value.log_type == "info") && (!String.IsNullOrEmpty(value.message)))
     {
         log item = new log
         {
             message     = value.message,
             log_type    = value.log_type,
             create_Date = DateTime.Now.ToString()
         };
         _context.Add(item);
         _context.SaveChanges();
         Response.StatusCode = 200;
     }
     else
     {
         Response.StatusCode = 400;
     }
 }
Esempio n. 9
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            try
            {
                using (LogContext db = new LogContext(dbContextOptions))
                {
                    using (IDbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        LogRow row = new LogRow
                        {
                            Level    = logLevel,
                            Category = categoryName,
                            EventID  = eventId.Id,
                            Message  = formatter(state, exception)
                        };

                        StringBuilder exceptionMessage = new();
                        while (exception != null)
                        {
                            exceptionMessage.AppendLine(exception.Message);
                            exceptionMessage.AppendLine(exception.StackTrace);

                            exception = exception.InnerException;
                        }
                        row.Exception = exceptionMessage.ToString();

                        db.Add(row);
                        db.SaveChanges();

                        transaction.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"{DateTime.Now} - ERROR: Failed to add log entry to database. ({ex.GetType().FullName}: {ex.Message})");
            }
        }
Esempio n. 10
0
        public void OnResourceExecuted(ResourceExecutedContext context)
        {
            Debug.WriteLine("LOGFILTER Executed");
            Log log = new Log
            {
                HttpStatusCode = context.HttpContext.Response.StatusCode,
                TimeOfLog      = DateTime.Now,
                RequestId      = Guid.NewGuid(),
                Request        = context.HttpContext.Request.Scheme,
                Response       = context.HttpContext.Response.ContentType
            };

            LogContext logContext = new LogContext();

            logContext.Add(log);
            logContext.SaveChanges();

            context.HttpContext.Items.Add("Log", log);
        }
Esempio n. 11
0
 public int Add(Log log, out string Error)
 {
     return(_logContext.Add(log, out Error));
 }
Esempio n. 12
0
 public void Add(Log entity)
 {
     _context.Add(entity);
 }