Exemple #1
0
        public void CreateLoggerFile()
        {
            LoggerTools.CreateFile();

            string path = LoggerTools.GetFilePath();

            Assert.True(File.Exists(path));
        }
Exemple #2
0
        public void GetLoggerFilePath()
        {
            string path         = LoggerTools.GetFilePath();
            string relativePath = Path.Combine(App.AppDir, @"../data.log");
            string expectedPath = Path.GetFullPath(relativePath);

            Assert.AreEqual(expectedPath, path);
        }
Exemple #3
0
        public void ClearLoggerFile()
        {
            LoggerTools.ClearFile();

            string path   = LoggerTools.GetFilePath();
            string result = File.ReadAllText(path);

            Assert.IsEmpty(result);
        }
Exemple #4
0
        public void LogException()
        {
            Exception e = new Exception("Uh-Oh, something broke!");

            JetLogger.LogException(e);

            string path   = LoggerTools.GetFilePath();
            string result = File.ReadAllText(path);

            Assert.That(result.Contains(e.Message));
        }
Exemple #5
0
        public void LogText()
        {
            string text = "JetWallet is a Bitcoin Wallet for Windows Desktop.";

            JetLogger.Log(text);

            string path   = LoggerTools.GetFilePath();
            string result = File.ReadAllText(path);

            Assert.That(result.Contains(text));
        }
        public async Task Invoke(HttpContext httpContext)
        {
            var request = httpContext.Request;

            if (request.Path.Value.ToLower().Contains("api"))
            {
                //var ip = GetClientIP(httpContext);

                //请求数据
                var requestData = request.QueryString.ToString();
                if (request.Method.ToLower().Equals("post"))
                {
                    request.EnableBuffering();
                    var reader = new StreamReader(request.Body);
                    requestData = await reader.ReadToEndAsync();

                    request.Body.Position = 0;
                }

                //var t = request.Cookies["token"];

                //响应数据
                Stream originalBody = httpContext.Response.Body;
                using (var ms = new MemoryStream())
                {
                    httpContext.Response.Body = ms;

                    await _next(httpContext);

                    ms.Position = 0;
                    var responseData = new StreamReader(ms).ReadToEnd();
                    ms.Position = 0;

                    await ms.CopyToAsync(originalBody);

                    LoggerTools.GetInstance(LoggerTools.RequestLog).RequestInfo(null, httpContext.Request.Path.Value, requestData, responseData);
                }
            }
            else
            {
                await _next(httpContext);
            }
        }
Exemple #7
0
 public JSONFormatter()
 {
     this.tools = new LoggerTools();
 }
Exemple #8
0
        public void Clear()
        {
            string path = LoggerTools.GetFilePath();

            File.Delete(path);
        }