public static Serilog.ILogger GetSerilogLogger(this IConfiguration configuration)
        {
            var baseDir = AppDomain.CurrentDomain.BaseDirectory;
            var logDir  = Path.Combine(baseDir, "Logs");
            var logfile = Path.Combine(logDir, "log.txt");

            Serilog.LoggerConfiguration loggerConfig =
                new LoggerConfiguration()
                .ReadFrom.Configuration(configuration, "Logging");

            var          splunkSection = configuration.GetSection("CommonSettings:SplunkConfig");
            SplunkConfig splunkConfig  = new SplunkConfig();

            splunkSection.Bind(splunkConfig);

            var cfg = loggerConfig
                      .Enrich.FromLogContext()
                      .WriteTo.Console(outputTemplate: loggerTemplate, theme: AnsiConsoleTheme.Literate)
                      .WriteTo.Debug()
                      .WriteTo.File(logfile, outputTemplate: loggerTemplate, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 90);

            if (splunkConfig.IsValid())
            {
                cfg = cfg.WriteTo.EventCollector(splunkConfig.Uri, splunkConfig.Token);
            }

            Log.Logger = cfg.CreateLogger();

            return(Log.Logger);
        }
            private SplunkConfig LoadTestConfig(Mock <IFileSystem> mockFileSystem)
            {
                var config = new SplunkConfig();

                mockFileSystem.Setup(fs => fs.FileExists(It.IsAny <string>())).Returns(true);
                mockFileSystem.Setup(fs => fs.ReadFileLines(It.IsAny <string>())).Returns(TestConfigLoader.GetSplunkRC());
                var loader = new SplunkConfigLoader(mockFileSystem.Object);

                loader.Load(config);
                return(config);
            }
Esempio n. 3
0
        public SplunkPack(IFileSystem fileSystem)
        {
            Guard.AgainstNullArgument("fileSystem", fileSystem);

            Config      = new SplunkConfig();
            _fileSystem = fileSystem;
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
            {
                return(true);
            };
        }
            public void ThrowsAnExceptionIfTheFileDoesNotExist(Mock <IFileSystem> mockFileSystem, SplunkConfig config)
            {
                mockFileSystem.Setup(f => f.FileExists(It.IsAny <string>())).Returns(false);
                var loader = new SplunkConfigLoader(mockFileSystem.Object, "test");

                Assert.Throws <FileNotFoundException>(() => loader.Load(config));
            }