public async Task <IActionResult> PostLogEntry([FromBody] JObject form) { //logEntry.ExceptionTrace = new Exception(); //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} try { dynamic logEntryForm = form; var logEntry = new LogEntryTranfer { LogCategoryParametre = logEntryForm.LogCategoryParametre, LogLevelShortName = logEntryForm.LogLevelShortName, }; var logLevelID = db.LogLevels.FirstOrDefault(l => l.ShortName.Contains(logEntry.LogLevelShortName)).LogLevelId; var logCategoryID = db.LogCategories.FirstOrDefault(l => l.ParameterValue.Contains(logEntry.LogCategoryParametre)).LogCategoryId; if (logLevelID.Equals(null) || logCategoryID.Equals(null)) { return(BadRequest()); } db.Add(new LogEntry { UserName = logEntryForm.UserName, ApplicationName = logEntryForm.ApplicationName, ExceptionTrace = (logEntry.ExceptionTrace != null) ? LogEntryHelper.GetAllErrorMsq(logEntry.ExceptionTrace) : null, LogCategoryId = logCategoryID, LogLevelId = logLevelID, LogDate = DateTime.Now, MachineIP = LogNetworkHelper.GetRemoteIpClientAddress(), MachineName = LogNetworkHelper.GetClientMachineName(), Message = logEntryForm.Message, ObjEntityId = logEntryForm.EntityID }); await db.SaveChangesAsync(); return(Ok("Ok")); } catch (Exception ex) { return(BadRequest(ex)); } }
public void AddLog(Log log) { _context.Add(log); _context.SaveChanges(); }