public IHttpActionResult Post() { #region LOGGER: Block for refactoring // ====================================================== // ------------------------------------------------------ DateTime start = DateTime.Now; Client clt = new Client() { Ip = "127.0.0.1", Agent = "Chrome" }; Account acc = new Account() { UserId = 0, Role = null, Login = null }; ClaimsPrincipal identity = (ClaimsPrincipal)Thread.CurrentPrincipal; acc.UserId = Convert.ToInt32(identity.Claims.Where(c => c.Type == "id").Select(c => c.Value).SingleOrDefault()); acc.Role = identity.Claims.Where(c => c.Type == "role").Select(c => c.Value).SingleOrDefault(); acc.Login = identity.Claims.Where(c => c.Type == "login").Select(c => c.Value).SingleOrDefault(); if (acc.Role == null) { acc.Role = "Public"; } if (acc.Login == null) { acc.Login = "******"; } var text = "{\"lvl\":\"TRACE\",\"time\":\"" + String.Format("{0:HH:mm:ss.fff}", DateTime.Now).ToString() + "\",\"userId\":" + acc.UserId + ",\"login\":\"" + acc.Login + "\",\"role\":\"" + acc.Role + "\",\"act\":\"LOGOUT\",\"ip\":\"" + clt.Ip + "\",\"agent\":\"" + clt.Agent + "\",\"lag\":" + (DateTime.Now - start).Milliseconds.ToString() + ",\"stat\":200,\"message\":\"Ok\"},"; Logger log = LogManager.GetCurrentClassLogger(); log.Trace(text); // ------------------------------------------------------ // ====================================================== #endregion //Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType); return Ok(); }
private void Log( int start, string lvl, string act, Account acc, Client clt, int stat, string mes ) { string time = String.Format("{0:HH:mm:ss.fff}", DateTime.Now).ToString(); int lag = (DateTime.Now.Millisecond - start); var text = "{" + "\"lvl\":\"" + lvl + "\"," + "\"time\":\"" + time + "\"," + "\"userId\":" + acc.UserId.ToString() + "," + "\"login\":\"" + acc.Login + "\"," + "\"role\":\"" + acc.Role + "\"," + "\"act\":\"" + act + "\"," + "\"ip\":\"" + clt.Ip + "\"," + "\"agent\":\"" + clt.Agent + "\"," + "\"lag\":" + lag.ToString() + "," + "\"stat\":" + stat.ToString() + "," + "\"message\":\"" + mes + "\"" + "},"; Logger log = LogManager.GetCurrentClassLogger(); log.Trace(text); }
private Account Acc(ClaimsPrincipal identity) { Account acc = new Account() { UserId = 0, Role = null, Login = null}; acc.UserId = Convert.ToInt32(identity.Claims.Where(c => c.Type == "id").Select(c => c.Value).SingleOrDefault()); acc.Role = identity.Claims.Where(c => c.Type == "role").Select(c => c.Value).SingleOrDefault(); acc.Login = identity.Claims.Where(c => c.Type == "login").Select(c => c.Value).SingleOrDefault(); if (acc.Role == null) { acc.Role = "Public"; } if (acc.Login == null) { acc.Login = "******"; } return acc; }