Пример #1
0
        private SiteLog StandardDBEntry()
        {
            SiteLog logEntry = new SiteLog();
            logEntry.TimeStamp = DateTime.UtcNow.AddHours(-5);

            if (HttpContext.Current != null && HttpContext.Current.Session != null)
                logEntry.SessionId = HttpContext.Current.Session.SessionID;

            try
            {

                if (HttpContext.Current != null && HttpContext.Current.Request != null && HttpContext.Current.User != null && HttpContext.Current.User.Identity != null)
                    logEntry.Custom = "User="******", Host=" +
                                    HttpContext.Current.Request.UserHostName + ", URL=" +
                                    HttpContext.Current.Request.RawUrl + ", Form=" +
                                    HttpContext.Current.Request.Form.ToString() + ", Referrer=" +
                                    HttpContext.Current.Request.UrlReferrer;
            }
            catch (System.Web.HttpException e)
            {
                logEntry.Custom = "Abject object failure. Probably startup. Msg: " + e.Message;
            }

            logEntry.ThreadID = Thread.CurrentThread.ManagedThreadId.ToString();
            if (HttpContext.Current.User != null)
                logEntry.UserName = HttpContext.Current.User.Identity.Name;
            else
                logEntry.UserName = "";

            return logEntry;
        }
Пример #2
0
 private void AddEntryToLog(SiteLog logEntry)
 {
     MakeStringsLenSafe(logEntry);
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #3
0
        private void SimpleLogTest(SiteLog logEntry)
        {
            TestTraceMessage("MLW In Trace: Lengths are: Custom=" + logEntry.Custom.Length);
            TestTraceMessage("MLW In Trace: Custom string is " + logEntry.Custom);
            TestTraceCustom(logEntry.Custom.Substring(0, Math.Min(100, logEntry.Custom.Length - 1)));

            TestTraceLevel(logEntry.Level);
            TestTraceSessionID(logEntry.SessionId);
            TestTraceTimeStamp(logEntry.TimeStamp);
            TestTraceThreadID(logEntry.ThreadID);
            TestTraceUserName(logEntry.UserName);
        }
Пример #4
0
 public void TestTraceUserName(string user)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.UserName = user;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #5
0
 private static void MakeStringsLenSafe(SiteLog logEntry)
 {
     logEntry.ExceptionMsg = logEntry.ExceptionMsg.Truncate(EXMSG_MAX_LEN);
     logEntry.ExceptionStack = logEntry.ExceptionStack.Truncate(EXSTACK_MAX_LEN);
     logEntry.ExceptionType = logEntry.ExceptionType.Truncate(EXTYPE_MAX_LEN);
     logEntry.Custom = logEntry.Custom.Truncate(CUSTOM_MAX_LEN);
     logEntry.Message = logEntry.Message.Truncate(MESSAGE_MAX_LEN);
     logEntry.SessionId = logEntry.SessionId.Truncate(SESSIONID_MAX_LEN);
     logEntry.UserName = logEntry.UserName.Truncate(USERNAME_MAX_LEN);
     logEntry.Level = logEntry.Level.Truncate(LEVEL_MAX_LEN);
     logEntry.ThreadID = logEntry.ThreadID.Truncate(THREADID_MAX_LEN);
 }
Пример #6
0
 public void TestTraceThreadID(string threadID)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.ThreadID = threadID;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #7
0
 public void TestTraceTimeStamp(DateTime? timeStamp)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.TimeStamp = timeStamp;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #8
0
 public void TestTraceMessage(string message)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.Message = message;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #9
0
 public void TestTraceSessionID(string sessionID)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.SessionId = sessionID;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #10
0
 public void TestTraceLevel(string lvl)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.Level = lvl;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #11
0
 public void TestTraceExceptionType(string exType)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.ExceptionType = exType;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #12
0
 public void TestTraceExceptionStack(string exStack)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.ExceptionStack = exStack;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #13
0
 public void TestTraceExceptionMsg(string exMsg)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.ExceptionMsg = exMsg;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }
Пример #14
0
 public void TestTraceCustom(string custom)
 {
     SiteLog logEntry = new SiteLog();
     logEntry.Custom = custom;
     _db.SiteLogs.Add(logEntry);
     _db.SaveChanges();
 }