public void LogEvent(LogLevel debugLevel, SecurityEventType securityEvent, string message, Exception ex)
        {
            var newEvent = new SecurityEventLog();

            newEvent.SecurityLevel = (int)securityEvent.EventLevel;
            newEvent.EventId       = securityEvent.EventId;

            if (_httpContext.User != null)
            {
                newEvent.LoggedInUserId = _httpContext.User.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
            }

            newEvent.RequestIpaddress = _httpContext.Connection.RemoteIpAddress.ToString();
            newEvent.RequestPort      = _httpContext.Connection.RemotePort;
            newEvent.RequestPath      = _httpContext.Request.Path;
            newEvent.RequestQuery     = _httpContext.Request.QueryString.ToString();

            string userAgent = !_httpContext.Request.Headers.ContainsKey("User-Agent") ? "" : _httpContext.Request.Headers["User-Agent"].ToString();

            if (userAgent.Length > 1000)
            {
                userAgent = userAgent.Substring(0, 1000);
            }

            newEvent.UserAgent       = userAgent;
            newEvent.CreatedDateTime = DateTime.UtcNow;
            newEvent.AdditionalInfo  = message;
            newEvent.StackTrace      = ex.ToString();

            _dbContext.SecurityEventLog.Add(newEvent);
            _dbContext.SaveChanges();
        }
Example #2
0
 private void Awake()
 {
     alarmLight              = GetComponent <Animation>();
     mainController          = this;
     path                    = Application.dataPath + FileName;
     onSecuritySystemChanged = new SecurityEventLog();
     onSecuritySystemChanged.AddListener(WriteLog);
     onAlarm.AddListener(StartAlarmLights);
 }