public void NormalizeLogsDirectoryPathReturnsFullyQualifiedPath(string logsDirectoryPath)
        {
            var    listener = new LocalTextFileListener(logsDirectoryPath);
            string path     = listener.NormalizeLogsDirectoryPath(logsDirectoryPath);

            Assert.IsTrue(Path.IsPathRooted(path));
        }
        public void GetFileNameReflectsTheFileName(FlushTrigger flushTrigger)
        {
            string filename          = $"{Guid.NewGuid()}.log";
            string logsDirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tests", $"logs-{Guid.NewGuid()}");
            var    listener          = new LocalTextFileListener(logsDirectoryPath, flushTrigger)
            {
                GetFileName = () => filename
            };

            FlushLogArgs flushLogArgs = CommonTestHelpers.Factory.CreateFlushLogArgs();

            listener.OnFlush(flushLogArgs);

            try
            {
                Assert.IsTrue(File.Exists(Path.Combine(logsDirectoryPath, filename)));
            }
            finally
            {
                if (Directory.Exists(logsDirectoryPath))
                {
                    Directory.Delete(logsDirectoryPath, true);
                }
            }
        }
        public void GetFileNameIsNotNull()
        {
            var    listener = new LocalTextFileListener("logs");
            string fileName = listener.GetFileName();

            Assert.IsFalse(string.IsNullOrWhiteSpace(fileName));
        }
Пример #4
0
        private void ConfigureKissLog()
        {
            // optional KissLog configuration
            KissLogConfiguration.Options
            .AppendExceptionDetails((Exception ex) =>
            {
                StringBuilder sb = new StringBuilder();

                if (ex is NullReferenceException nullRefException)
                {
                    sb.AppendLine("Important: check for null references");
                }

                return(sb.ToString());
            })
            .GenerateSearchKeywords((FlushLogArgs args) =>
            {
                var service = new GenerateSearchKeywordsService();
                IEnumerable <string> keywords = service.GenerateKeywords(args);

                return(keywords);
            });

            // KissLog internal logs
            KissLogConfiguration.InternalLog = (message) =>
            {
                Debug.WriteLine(message);
            };

            // register listeners
            KissLogConfiguration.Listeners
            .Add(new RequestLogsApiListener(new Application(ConfigurationManager.AppSettings["KissLog.OrganizationId"], ConfigurationManager.AppSettings["KissLog.ApplicationId"]))
            {
                ApiUrl      = ConfigurationManager.AppSettings["KissLog.ApiUrl"],
                Interceptor = new StatusCodeInterceptor
                {
                    MinimumLogMessageLevel        = LogLevel.Trace,
                    MinimumResponseHttpStatusCode = 200
                },
                OnException = (ExceptionArgs args) =>
                {
                    var listener = new LocalTextFileListener("logs", FlushTrigger.OnFlush);
                    listener.OnFlush(args.FlushArgs);
                }
            })
            .Add(new LocalTextFileListener("Logs_onFlush", FlushTrigger.OnFlush))
            .Add(new LocalTextFileListener("Logs_onMessage", FlushTrigger.OnMessage));
        }
        public void GetFilePathCreatesTheDirectoryIfDoesntExist()
        {
            string logsDirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tests", $"logs-{Guid.NewGuid()}");

            var listener = new LocalTextFileListener(logsDirectoryPath);

            listener.GetFilePath();

            try
            {
                Assert.IsTrue(Directory.Exists(logsDirectoryPath));
            }
            finally
            {
                if (Directory.Exists(logsDirectoryPath))
                {
                    Directory.Delete(logsDirectoryPath, true);
                }
            }
        }
 public void NullTextFormatterThrowsException(FlushTrigger flushTrigger)
 {
     var listener = new LocalTextFileListener("logs", flushTrigger, null);
 }
 public void LogsDirectoryPathDoesNotThrowException(string logsDirectoryPath)
 {
     var listener = new LocalTextFileListener(logsDirectoryPath);
 }
 public void ConstructorThrowsExceptionForNullTextFormatter()
 {
     var localTextFileListener = new LocalTextFileListener("logs");
     var listener = new FlushTextFileListener(localTextFileListener, null);
 }