public void WithArchiveCount_SetArchiveCountProperty(int archiveCount)
        {
            // Arrange
            var sut = new LoggerOptions();

            // Act
            sut.WithArchiveCount(archiveCount);

            // Assert
            sut.ArchiveCount.Should().Be(archiveCount);
        }
        public void ArchiveOnStart_SetArchiveOnStartProperty(bool archive)
        {
            // Arrange
            var sut = new LoggerOptions();

            // Act
            sut.ArchiveOnStart(archive);

            // Assert
            sut.IsArchiveOnStart.Should().Be(archive);
        }
 public EtlXmlOptions(ArchiveOptions archiveOptions, CryptingOptions cryptingOptions, LoggerOptions loggerOptions, WatcherOptions watcherOptions, Options defaultOptions)
 {
     ArchiveOptions  = archiveOptions;
     CryptingOptions = cryptingOptions;
     LoggerOptions   = loggerOptions;
     WatcherOptions  = watcherOptions;
     DefaultOptions  = defaultOptions;
     SourceDirectory = DefaultOptions.SourceDirectory;
     TargetDirectory = DefaultOptions.TargetDirectory;
     IsLoggerEnable  = DefaultOptions.IsLoggerEnable;
 }
        public void Compress_SetIsCompressedProperty(bool isCompressed)
        {
            // Arrange
            var sut = new LoggerOptions();

            // Act
            sut.Compress(isCompressed);

            // Assert
            sut.IsCompressed.Should().Be(isCompressed);
        }
        public void WithDefaultLogMessagelayout_SetLogMessageLayoutProperty_ToDefault()
        {
            // Arrange
            var sut = new LoggerOptions();

            // Act
            sut.WithDefaultLogMessagelayout();

            // Assert
            sut.LogMessageLayout.Should().BeNull();
        }
        public void WithLevel_SetLogLevelProperty(LogLevel level)
        {
            // Arrange
            var sut = new LoggerOptions();

            // Act
            sut.WithLevel(level);

            // Assert
            sut.Level.Should().Be(level);
        }
        public void RemoveDebugTarget_SetLogMessageLayoutProperty_ToFalse()
        {
            // Arrange
            var sut = new LoggerOptions();

            // Act
            sut.RemoveDebugTarget();

            // Assert
            sut.LogToDebugStream.Should().BeFalse();
        }
        public void DoesNotThrowExceptionWhenFactoryIsNull()
        {
            var options = new LoggerOptions
            {
                Factory = null
            };

            ILogger adapter = new LoggerAdapter(options);

            adapter.Log(Microsoft.Extensions.Logging.LogLevel.Debug, 10, new { }, null, (state, ex) => { return("Default formatter message"); });
        }
Example #9
0
        public void LoggerTest()
        {
            _loggerOptions = BindHelpers.FillLoggerOptions();
            var options = Options.Create(_loggerOptions);

            _loggerService = new LoggerService(options);

            Action action = () => _loggerService.LogMessage("hi..", MessageType.Error);

            AssertHelpers.DoesNotThrows <Exception>(action);
        }
Example #10
0
        public void AddDebugTarget_SetLogMessageLayoutProperty(bool debug)
        {
            // Arrange
            var sut = new LoggerOptions();

            // Act
            sut.AddDebugTarget(debug);

            // Assert
            sut.LogToDebugStream.Should().Be(debug);
        }
Example #11
0
        public Logger(LoggerOptions options)
        {
            enableConsoleLogging = options.EnableConsoleLogging;

            var filePath = options.FilePath;

            if (filePath != null)
            {
                file = File.OpenWrite(filePath);
            }
        }
Example #12
0
        public void WithLogMessageLayout_WithNullOrEmptyLayout_SetLogMessageLayoutProperty_ToDefault(
            string logMessageLayout)
        {
            // Arrange
            var sut = new LoggerOptions();

            // Act
            sut.WithLogMessageLayout(logMessageLayout);

            // Assert
            sut.LogMessageLayout.Should().BeNull();
        }
Example #13
0
        public void WithFilter_SetFilterProperty()
        {
            // Arrange
            var filter = Guid.NewGuid().ToString();
            var sut    = new LoggerOptions();

            // Act
            sut.WithFilter(filter);

            // Assert
            sut.Filter.Should().Be(filter);
        }
Example #14
0
        public void WithFile_SetFileNameProperty()
        {
            // Arrange
            var fileName = Guid.NewGuid().ToString();
            var sut      = new LoggerOptions();

            // Act
            sut.WithFile(fileName);

            // Assert
            sut.FileName.Should().Be(fileName);
        }
Example #15
0
        public void WithLogMessageLayout_SetLogMessageLayoutProperty()
        {
            // Arrange
            var logMessageLayout = Guid.NewGuid().ToString();
            var sut = new LoggerOptions();

            // Act
            sut.WithLogMessageLayout(logMessageLayout);

            // Assert
            sut.LogMessageLayout.Should().Be(logMessageLayout);
        }
Example #16
0
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            var labels = new Dictionary <string, string> {
                { "some-key", "some-value" }
            };

            SetupRoutes(app);
            LoggerOptions loggerOptions = LoggerOptions.Create(
                LogLevel.Warning, null, labels, null, BufferOptions.NoBuffer());

            loggerFactory.AddGoogle(app.ApplicationServices, ProjectId, loggerOptions);
        }
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Main}/{action=Index}/{id}");
            });
            LoggerOptions loggerOptions = LoggerOptions.Create(
                LogLevel.Warning, null, null, null, BufferOptions.NoBuffer());

            loggerFactory.AddGoogle(app.ApplicationServices, _projectId, loggerOptions);
        }
        /// <summary>
        /// Create an <see cref="ILoggerProvider"/> for Google Stackdriver Logging.
        /// </summary>
        /// <param name="logTarget">Where to log to. Must not be null.</param>
        /// <param name="serviceProvider">Optional, the service provider to resolve additional services from. May be null,
        /// in which case additional services (such as custom labels) will not be used.</param>
        /// <param name="options">Optional, options for the logger.</param>
        /// <param name="client">Optional, logging client.</param>
        public static GoogleLoggerProvider Create(LogTarget logTarget, IServiceProvider serviceProvider,
                                                  LoggerOptions options = null, LoggingServiceV2Client client = null)
        {
            // Check params and set defaults if unset.
            GaxPreconditions.CheckNotNull(logTarget, nameof(logTarget));
            client  = client ?? LoggingServiceV2Client.Create();
            options = options ?? LoggerOptions.Create();

            // Get the proper consumer from the options and add a logger provider.
            IConsumer <LogEntry> consumer = LogConsumer.Create(client, options.BufferOptions, options.RetryOptions);

            return(new GoogleLoggerProvider(consumer, logTarget, options, serviceProvider));
        }
 internal GoogleLogger(IConsumer <LogEntry> consumer, LogTarget logTarget, LoggerOptions loggerOptions,
                       string logName, IClock clock = null, IServiceProvider serviceProvider = null)
 {
     _logTarget   = GaxPreconditions.CheckNotNull(logTarget, nameof(logTarget));
     _traceTarget = logTarget.Kind == LogTargetKind.Project ?
                    TraceTarget.ForProject(logTarget.ProjectId) : null;
     _consumer        = GaxPreconditions.CheckNotNull(consumer, nameof(consumer));
     _loggerOptions   = GaxPreconditions.CheckNotNull(loggerOptions, nameof(loggerOptions));
     _logName         = GaxPreconditions.CheckNotNullOrEmpty(logName, nameof(logName));
     _fullLogName     = logTarget.GetFullLogName(_loggerOptions.LogName);
     _serviceProvider = serviceProvider;
     _clock           = clock ?? SystemClock.Instance;
 }
Example #20
0
        public static void AddLoggerService(this IServiceCollection services, IConfiguration configuration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var LoggerOptions = new LoggerOptions();

            new ConfigureFromConfigurationOptions <LoggerOptions>(configuration.GetSection("LogOptions"))
            .Configure(LoggerOptions);

            services.AddSingleton(LoggerOptions);
        }
Example #21
0
        private GoogleLogger GetLogger(
            IConsumer <LogEntry> consumer      = null, LogLevel logLevel = LogLevel.Information,
            Dictionary <string, string> labels = null, IServiceProvider serviceProvider = null,
            string logName = null,
            MonitoredResource monitoredResource = null, LogTarget logTarget = null,
            RetryOptions retryOptions           = null)
        {
            consumer          = consumer ?? new Mock <IConsumer <LogEntry> >(MockBehavior.Strict).Object;
            monitoredResource = monitoredResource ?? MonitoredResourceBuilder.GlobalResource;
            logTarget         = logTarget ?? s_defaultLogTarget;
            LoggerOptions options = LoggerOptions.Create(logLevel, logName, labels, monitoredResource, retryOptions: retryOptions);

            return(new GoogleLogger(consumer, logTarget, options, LogName, s_clock, serviceProvider));
        }
        public static Serilog.ILogger CreateLoggerConsole(Action <LoggerOptions> optionBuilder)
        {
            var loggerOptions = new LoggerOptions();

            optionBuilder.Invoke(loggerOptions);

            var logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .Enrich.WithExceptionDetails()
                         .Enrich.WithProperty("ApplicationName", loggerOptions.AppName)
                         .WriteTo.Console();

            return(logger.CreateLogger());
        }
        public void AutoFlushReturnsTrueIfLoggerIsManagedByHttpRequestIsTrue(bool isManagedByHttpRequest)
        {
            Logger kisslogger = new Logger();

            kisslogger.DataContainer.LoggerProperties.IsManagedByHttpRequest = isManagedByHttpRequest;

            var options = new LoggerOptions
            {
                Factory = new KissLog.LoggerFactory(kisslogger)
            };

            ILogger logger = new LoggerAdapter(options);

            Assert.AreEqual(isManagedByHttpRequest, logger.AutoFlush());
        }
        public void LogResponseBodyUpdatesTheLoggerProperties(bool value)
        {
            Logger kisslogger = new Logger();

            var options = new LoggerOptions
            {
                Factory = new KissLog.LoggerFactory(kisslogger)
            };

            ILogger logger = new LoggerAdapter(options);

            logger.LogResponseBody(value);

            Assert.AreEqual(value, kisslogger.DataContainer.LoggerProperties.ExplicitLogResponseBody.Value);
        }
        public void SetStatusCodeUpdatesTheLoggerProperties(int statusCode)
        {
            Logger kisslogger = new Logger();

            var options = new LoggerOptions
            {
                Factory = new KissLog.LoggerFactory(kisslogger)
            };

            ILogger logger = new LoggerAdapter(options);

            logger.SetStatusCode(statusCode);

            Assert.AreEqual(statusCode, kisslogger.DataContainer.LoggerProperties.ExplicitStatusCode.Value);
        }
Example #26
0
        static void TestLogger()
        {
            LoggerOptions loggerOptions = new LoggerOptions()
            {
                OutputToConsole = true,
                OutputToFile    = true,
                OutputToWebAPI  = false,
                LogFile         = "test.log",
                WebAPIUrl       = "http://localhost/"
            };

            Logger.Instance.Init(loggerOptions);
            Logger.Instance.Log("Wow", LogLevel.Error);
            Logger.Instance.Log("test", LogLevel.Info);
        }
Example #27
0
    private static void Configure(LoggerConfiguration loggerConfiguration, LogEventLevel level,
                                  LoggerOptions options)
    {
        var consoleOptions = options.Console ?? new ConsoleOptions();
        var fileOptions    = options.File ?? new Options.FileOptions();
        var elkOptions     = options.Elk ?? new ElkOptions();
        var seqOptions     = options.Seq ?? new SeqOptions();

        if (consoleOptions.Enabled)
        {
            loggerConfiguration.WriteTo.Console();
        }

        if (fileOptions.Enabled)
        {
            var path = string.IsNullOrWhiteSpace(fileOptions.Path) ? Path.Combine("logs", "logs.log") : fileOptions.Path;
            if (!Enum.TryParse <RollingInterval>(fileOptions.Interval,
                                                 true, out var interval))
            {
                interval = RollingInterval.Day;
            }

            loggerConfiguration.WriteTo.File(path, rollingInterval: interval);
        }

        if (elkOptions.Enabled)
        {
            loggerConfiguration.WriteTo.Elasticsearch(
                new ElasticsearchSinkOptions(new Uri(elkOptions.Url))
            {
                MinimumLogEventLevel        = level,
                AutoRegisterTemplate        = true,
                AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
                IndexFormat = string.IsNullOrWhiteSpace(elkOptions.IndexFormat)
                    ? "logstash-{0:yyyy.MM.dd}"
                    : elkOptions.IndexFormat,
                ModifyConnectionSettings = connectionConfiguration =>
                                           elkOptions.BasicAuthEnabled
                            ? connectionConfiguration.BasicAuthentication(elkOptions.Username, elkOptions.Password)
                            : connectionConfiguration
            });
        }

        if (seqOptions.Enabled)
        {
            loggerConfiguration.WriteTo.Seq(seqOptions.Url, apiKey: seqOptions.ApiKey);
        }
    }
Example #28
0
        private static IWebHostBuilder GetExceptionPropagatingHostBuilder()
        {
            string projectId = "non-existent-project-id";
            // Sample: RegisterGoogleLoggerPropagateExceptions
            // Explicitly create logger options that will propagate any exceptions thrown
            // during logging.
            RetryOptions retryOptions = RetryOptions.NoRetry(ExceptionHandling.Propagate);
            // Also set the no buffer option so that writing the logs is attempted immediately.
            BufferOptions bufferOptions = BufferOptions.NoBuffer();
            LoggerOptions loggerOptions = LoggerOptions.Create(bufferOptions: bufferOptions, retryOptions: retryOptions);

            return(new WebHostBuilder()
                   .UseGoogleDiagnostics(projectId, loggerOptions: loggerOptions)
                   .UseStartup <Startup>());
            // End sample
        }
Example #29
0
        public void AddBoolean()
        {
            Logger kisslogger = new Logger();

            var options = new LoggerOptions
            {
                Factory = new KissLog.LoggerFactory(kisslogger)
            };

            ILogger logger = new LoggerAdapter(options);

            logger.AddCustomProperty("boolean", true);

            Assert.AreEqual("boolean", kisslogger.DataContainer.LoggerProperties.CustomProperties[0].Key);
            Assert.AreEqual(true, kisslogger.DataContainer.LoggerProperties.CustomProperties[0].Value);
        }
Example #30
0
        /// <summary>
        /// Adds a <see cref="GoogleLoggerProvider"/> for <see cref="GoogleLogger"/>s.
        /// </summary>
        /// <param name="builder">The logger builder. Cannot be null.</param>
        /// <param name="serviceProvider">The service provider to resolve additional services from.</param>
        /// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine.
        ///     The Google Cloud Platform project ID. If unspecified and running on GAE or GCE the project ID will be
        ///     detected from the platform.</param>
        /// <param name="options">Optional, options for the logger.</param>
        /// <param name="client">Optional, logging client.</param>
        public static void AddGoogle(this ILoggingBuilder builder,
                                     IServiceProvider serviceProvider,
                                     string projectId              = null,
                                     LoggerOptions options         = null,
                                     LoggingServiceV2Client client = null)
        {
            GaxPreconditions.CheckNotNull(builder, nameof(builder));

            options   = options ?? LoggerOptions.Create();
            projectId = Project.GetAndCheckProjectId(projectId, options.MonitoredResource);
            LogTarget logTarget = LogTarget.ForProject(projectId);

            var provider = GoogleLoggerProvider.Create(serviceProvider, projectId, options, client);

            builder.Services.AddSingleton <ILoggerProvider>(provider);
        }