示例#1
0
        public void GDCTest2()
        {
            GDC.Clear();
            Assert.False(GDC.Contains("foo"));
            Assert.Equal(string.Empty, GDC.Get("foo"));
            Assert.False(GDC.Contains("foo2"));
            Assert.Equal(string.Empty, GDC.Get("foo2"));

            GDC.Set("foo", "bar");
            GDC.Set("foo2", "bar2");

            Assert.True(GDC.Contains("foo"));
            Assert.Equal("bar", GDC.Get("foo"));

            GDC.Remove("foo");
            Assert.False(GDC.Contains("foo"));
            Assert.Equal(string.Empty, GDC.Get("foo"));

            Assert.True(GDC.Contains("foo2"));
            Assert.Equal("bar2", GDC.Get("foo2"));

            Assert.Null(GDC.GetObject("foo3"));

            Assert.Equal(string.Empty, GDC.Get("foo3", null));
        }
示例#2
0
文件: Logger.cs 项目: dKluev/Site
        public static void Exception(Exception ex, string sysMessage)
        {
            GDC.Set("title", sysMessage);
            var builder = new StringBuilder();

            builder.AppendLine();
            if (!sysMessage.IsEmpty())
            {
                builder.AppendLine("sysmessage: " + sysMessage);
            }
            builder.AppendLine("type: " + ex.GetType());
            builder.AppendLine("message: " + ex.Message);
            builder.AppendLine("source: " + ex.Source);
            builder.AppendLine("targetSite: " + ex.TargetSite);
            builder.AppendLine("stackTrace: " + ex.StackTrace);
            var httpContext = HttpContext.Current;
            var request     = httpContext.GetOrDefault(x => x.Request);

            if (request != null)
            {
                builder.AppendLine("user-agent: " + request.UserAgent);
            }

            /*var trace = new System.Diagnostics.StackTrace(ex, true);
             *
             * if(trace.FrameCount > 0) {
             * var stackFrame = trace.GetFrame(0);
             *      builder.AppendLine("Line: " + stackFrame.GetFileLineNumber());
             *      builder.AppendLine("Column: " + stackFrame.GetFileColumnNumber());
             *
             * }*/
            LogManager.GetCurrentClassLogger().Error(builder.ToString());
        }
示例#3
0
        public void GDCTest2()
        {
            GDC.Clear();
            Assert.IsFalse(GDC.Contains("foo"));
            Assert.AreEqual(string.Empty, GDC.Get("foo"));
            Assert.IsFalse(GDC.Contains("foo2"));
            Assert.AreEqual(string.Empty, GDC.Get("foo2"));

            GDC.Set("foo", "bar");
            GDC.Set("foo2", "bar2");

            Assert.IsTrue(GDC.Contains("foo"));
            Assert.AreEqual("bar", GDC.Get("foo"));

            GDC.Remove("foo");
            Assert.IsFalse(GDC.Contains("foo"));
            Assert.AreEqual(string.Empty, GDC.Get("foo"));

            Assert.IsTrue(GDC.Contains("foo2"));
            Assert.AreEqual("bar2", GDC.Get("foo2"));
        }
示例#4
0
文件: Logger.cs 项目: dKluev/Site
        public static void Exception(Exception ex, User user)
        {
            var httpContext = HttpContext.Current;
            var request     = httpContext.GetOrDefault(x => x.Request);
            var statusCode  = httpContext.Response.StatusCode;

            if (statusCode == (int)HttpStatusCode.NotFound)
            {
                SpecLogger.NotFound(request.Url.ToString());
                return;
            }
            GDC.Set("title", "[" + statusCode + "] Custom " + request.Url);
            var builder = new StringBuilder();

            builder.AppendLine();
            builder.AppendLine("type: " + ex.GetType());
            builder.AppendLine("message: " + ex.Message);
            builder.AppendLine("source: " + ex.Source);
            if (user != null)
            {
                builder.AppendLine("user: "******" " + user.FullName);
            }
            if (httpContext.User != null)
            {
                builder.AppendLine("identity: " +
                                   httpContext.User.Identity.GetOrDefault(x => x.Name));
            }
            builder.AppendLine("userhost: " + request.UserHostAddress + " " +
                               request.UserHostName);
            try {
                builder.AppendLine("form: " + request.Form);
            }catch {}
            builder.AppendLine("url: " + request.Url);
            builder.AppendLine("referrer-url: " + request.UrlReferrer);
            builder.AppendLine("user-agent: " + request.UserAgent);
            builder.AppendLine("target-site: " + ex.TargetSite);
            builder.AppendLine("stack-trace: " + ex.StackTrace);
            LogManager.GetCurrentClassLogger().Error(builder.ToString());
        }
示例#5
0
文件: Logger.cs 项目: dKluev/Site
 public static void Error(string sysMessage)
 {
     GDC.Set("title", sysMessage);
     LogManager.GetCurrentClassLogger().Error(sysMessage);
 }