public static void LogMessage(string text, int paperId, int subLogId, string username)
 {
     lock (lockTrigger)
     {
         LogEntry e = new LogEntry();
         e.Message = text;
         e.subLogId = subLogId;
         e.TimeStamp = DateTime.Now;
         e.UserName = WebMatrix.WebData.WebSecurity.CurrentUserName;
         e.UserRole = AccountHelper.GetUserRole(WebMatrix.WebData.WebSecurity.CurrentUserId);
         e.StatusChanged = true;
         LogMessage(paperId, e);
         //string path = pathToWorkingDirectory + paperId + "/log.html";
         //string message = "id=\"" + (GetLastId(paperId, subLogId) + 1) + "\":" + subLogId + ":" + DateTime.Now.ToString("yyyy.MM.dd HH:mm") + " [b]" + username + "[/b]: " + text + "\r\n";
         //File.AppendAllText(path, message);
     }
 }
 public static void LogMessage(int paperId, LogEntry e)
 {
     lock (lockTrigger)
     {
         var context = GetContext(paperId);
         context.Log.Add(e);
         UpdateContext(context);
     }
 }
        public ActionResult Log(string text, int paperId, int subLogId, int lastLogId, string emailToRole = "noemail")
        {
            try
            {
                //logger.Info("lastLogLogId: " + lastLogId);
                //var result = File(System.Text.UnicodeEncoding.Default.GetBytes(Tools.PanelHelper.GetLogAfterId(paperId, lastLogId)), "text");
                //DateTime d = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                //d = d.AddMilliseconds(Convert.ToInt64(lastUpdateTime));
                //DateTime lastUpdate = d.ToLocalTime();

                //mail logic
                switch (emailToRole)
                {
                    case "toEditor":
                        subLogId = 0;
                        Tools.MailSender.SendMail("Новое сообщение", "Новое сообщение от " + Tools.AccountHelper.GetRoleTranslation(Tools.AccountHelper.GetUserRole(WebMatrix.WebData.WebSecurity.CurrentUserId)) + ".\r\n" + text, Tools.ConfigurationResourcesHelper.GetResource("mailinglist", "EditorMail"));
                        break;
                    case "toCorrector":
                        subLogId = 0;
                        Tools.MailSender.SendMail("Новое сообщение", "Новое сообщение от " + Tools.AccountHelper.GetRoleTranslation(Tools.AccountHelper.GetUserRole(WebMatrix.WebData.WebSecurity.CurrentUserId)) + ".\r\n" + text, Tools.ConfigurationResourcesHelper.GetResource("mailinglist", "CorrectorMail"));
                        break;
                    case "toUser":
                        subLogId = 0;
                        Tools.MailSender.SendMail("Новое сообщение", "Новое сообщение от " + Tools.AccountHelper.GetRoleTranslation(Tools.AccountHelper.GetUserRole(WebMatrix.WebData.WebSecurity.CurrentUserId)) + ".\r\n" + text, WebMatrix.WebData.WebSecurity.CurrentUserName);
                        break;
                    default:
                    case "noemail":
                        break;
                }
                LogEntry entry = new LogEntry();
                entry.Message = text;
                entry.subLogId = subLogId;
                entry.TimeStamp = DateTime.Now;
                entry.UserName = WebMatrix.WebData.WebSecurity.CurrentUserName;
                entry.UserRole = Tools.AccountHelper.GetUserRole(WebMatrix.WebData.WebSecurity.CurrentUserId);
                Tools.PanelHelper.LogMessage(paperId, entry);
                //Tools.PanelHelper.LogMessage(text, paperId, subLogId, Tools.AccountHelper.GetRoleTranslation(Tools.AccountHelper.GetUserRole(WebMatrix.WebData.WebSecurity.CurrentUserId)));
                return new HttpStatusCodeResult(HttpStatusCode.OK);
                //return Json(new { lastId = Tools.PanelHelper.GetLastId(paperId, subLogId), content = Tools.PanelHelper.GetWholeSubLogAfterId(paperId, subLogId, lastLogId) }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return File(System.Text.ASCIIEncoding.Default.GetBytes(ex.Message), "text");
            }
        }