Exemplo n.º 1
0
        public RavenTest()
        {
            BoundedMemoryTarget boundedMemoryTarget = null;

            if (LogManager.Configuration != null && LogManager.Configuration.AllTargets != null)
            {
                boundedMemoryTarget = LogManager.Configuration.AllTargets.OfType <BoundedMemoryTarget>().FirstOrDefault();
            }
            if (boundedMemoryTarget != null)
            {
                boundedMemoryTarget.Clear();
            }


            try
            {
                new Uri("http://fail/first/time?only=%2bplus");
            }
            catch (Exception)
            {
            }

            SystemTime.UtcDateTime = () => DateTime.UtcNow;

            ClearDatabaseDirectory();

            Directory.CreateDirectory(DbDirectory);
        }
Exemplo n.º 2
0
        public override void Respond(IHttpContext context)
        {
            BoundedMemoryTarget boundedMemoryTarget = null;

            if (LogManager.Configuration != null && LogManager.Configuration.AllTargets != null)
            {
                boundedMemoryTarget = LogManager.Configuration.AllTargets.OfType <BoundedMemoryTarget>().FirstOrDefault();
            }
            if (boundedMemoryTarget == null)
            {
                context.SetStatusToNotFound();
                context.WriteJson(new
                {
                    Error = "HttpEndpoint was not registered in the log configuration, logs endpoint disable"
                });
                return;
            }
            IEnumerable <LogEventInfo> log = boundedMemoryTarget.GeneralLog;

            switch (context.Request.QueryString["type"])
            {
            case "error":
            case "warn":
                log = boundedMemoryTarget.WarnLog;
                break;
            }

            context.WriteJson(log.Select(x => new
            {
                x.TimeStamp,
                Message = x.FormattedMessage,
                x.LoggerName,
                Level     = x.Level.Name,
                Exception = x.Exception == null ? null : x.Exception.ToString()
            }));
        }