public SplunkHttpEventCollectorTests()
        {
            // Step 1. Create configuration object
            var config = new LoggingConfiguration();

            // Step 2. Create target and add it to the configuration
            var splunkHttpEventCollector = new SplunkHttpEventCollector();

            config.AddTarget("splunkTarget", splunkHttpEventCollector);

            // Step 3. Set target properties
            splunkHttpEventCollector.ServerUrl      = new Uri("http://localhost:8088");
            splunkHttpEventCollector.Token          = "bff36dda-e0fc-4cdd-b2dc-50418ee98ead";
            splunkHttpEventCollector.RetriesOnError = 0;

            // Step 4. Define rules
            var rule1 = new LoggingRule("*", LogLevel.Trace, splunkHttpEventCollector);

            config.LoggingRules.Add(rule1);

            // Step 5. Activate the configuration
            LogManager.Configuration = config;
            LogManager.ReconfigExistingLoggers();

            // Step 6. Create logger
            _logger = NLog.LogManager.GetCurrentClassLogger();
        }
Exemple #2
0
        public SplunkHttpEventCollectorTests()
        {
            // Step 1. Create repository object
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            // Step 2. Create appender
            var splunkHttpEventCollector = new SplunkHttpEventCollector();

            // Step 3. Set appender properties
            splunkHttpEventCollector.ServerUrl      = "http://localhost:8088";
            splunkHttpEventCollector.Token          = "7856e3dd-b7d2-4b8f-b88e-61146264b727";
            splunkHttpEventCollector.RetriesOnError = 0;

            log4net.Layout.PatternLayout patternLayout = new log4net.Layout.PatternLayout
            {
                ConversionPattern = "%message"
            };
            patternLayout.ActivateOptions();

            splunkHttpEventCollector.Layout = patternLayout;

            splunkHttpEventCollector.ActivateOptions();

            // Step 4. Add appender to logger
            hierarchy.Root.AddAppender(splunkHttpEventCollector);
            hierarchy.Threshold  = Level.All;
            hierarchy.Configured = true;

            // Step 5. Create logger
            _logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }
        public SplunkHttpEventCollectorTests()
        {
            // Step 1. Create configuration object
            var config = new LoggingConfiguration();

            // Step 2. Create target and add it to the configuration
            var splunkHttpEventCollector = new SplunkHttpEventCollector();

            config.AddTarget("splunkTarget", splunkHttpEventCollector);

            // Step 3. Set target properties
            splunkHttpEventCollector.ServerUrl      = new Uri("http://localhost:8088");
            splunkHttpEventCollector.Token          = "b9e45a2a-1093-4572-9a9d-2ef2baabafb5";
            splunkHttpEventCollector.RetriesOnError = 0;
            splunkHttpEventCollector.Layout         = "${message}";

            // Step 4. Define rules
            var rule1 = new LoggingRule("*", LogLevel.Trace, splunkHttpEventCollector);

            config.LoggingRules.Add(rule1);

            // Step 5. Activate the configuration
            LogManager.Configuration = config;
            LogManager.ReconfigExistingLoggers();

            // Step 6. Create logger
            _logger = NLog.LogManager.GetCurrentClassLogger();
        }
Exemple #4
0
        public void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(Assembly.GetCallingAssembly());

            var eventCollector = new SplunkHttpEventCollector
            {
                ServerUrl               = ServerUrl,
                Token                   = Token,
                RetriesOnError          = RetriesOnError,
                IgnoreCertificateErrors = IgnoreCertificateErrors
            };
            PatternLayout patternLayout = new PatternLayout
            {
                ConversionPattern = ConversionPattern
            };

            patternLayout.ActivateOptions();
            eventCollector.Layout = patternLayout;
            eventCollector.ActivateOptions();

            hierarchy.Root.AddAppender(eventCollector);
            hierarchy.Threshold  = Level.All;
            hierarchy.Configured = true;

            logger = LogManager.GetLogger(GetType());
        }
        public CustomFormatterTest()
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            // Step 1. Create repository object
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            // Step 2. Create appender
            var splunkHttpEventCollector = new SplunkHttpEventCollector
            {
                SourceType = "json"
            };

            // Step 3. Set appender properties
            splunkHttpEventCollector.ServerUrl      = "https://localhost:8088";
            splunkHttpEventCollector.Token          = "ED9F5A37-BE9A-4782-B5F7-B6E31AC369CA";
            splunkHttpEventCollector.RetriesOnError = 0;

            log4net.Layout.PatternLayout patternLayout = new log4net.Layout.PatternLayout
            {
                ConversionPattern = "%message"
            };
            patternLayout.ActivateOptions();

            splunkHttpEventCollector.Layout = patternLayout;

            splunkHttpEventCollector.ActivateOptions(Formatter);

            // Step 4. Add appender to logger
            hierarchy.Root.AddAppender(splunkHttpEventCollector);
            hierarchy.Threshold  = Level.All;
            hierarchy.Configured = true;

            // Step 5. Create logger
            _logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }