/// <summary> /// Adds the AWS logging provider to the log factory using the configuration specified in the AWSLoggerConfig /// </summary> /// <param name="factory"></param> /// <param name="config">Configuration on how to connect to AWS and how the log messages should be sent.</param> /// <param name="filter">A filter function that has the logger category name and log level which can be used to filter messages being sent to AWS.</param> /// <returns></returns> public static ILoggerFactory AddAWSProvider(this ILoggerFactory factory, AWSLoggerConfig config, Func <string, LogLevel, bool> filter) { var provider = new AWSLoggerProvider(config, filter); factory.AddProvider(provider); return(factory); }
/// <summary> /// Adds the AWS logging provider to the log builder using the configuration specified in the AWSLoggerConfig /// </summary> /// <param name="builder"></param> /// <param name="config">Configuration on how to connect to AWS and how the log messages should be sent.</param> /// <param name="minLevel">The minimum log level for messages to be written.</param> /// <returns></returns> public static ILoggingBuilder AddAWSProvider(this ILoggingBuilder builder, AWSLoggerConfig config, LogLevel minLevel) { var provider = new AWSLoggerProvider(config, minLevel); builder.AddProvider(provider); return(builder); }
/// <summary> /// Adds the AWS logging provider to the log factory using the configuration specified in the AWSLoggerConfig /// </summary> /// <param name="factory"></param> /// <param name="config">Configuration on how to connect to AWS and how the log messages should be sent.</param> /// <param name="minLevel">The minimum log level for messages to be written.</param> /// <returns></returns> public static ILoggerFactory AddAWSProvider(this ILoggerFactory factory, AWSLoggerConfig config, LogLevel minLevel) { var provider = new AWSLoggerProvider(config, minLevel); factory.AddProvider(provider); return(factory); }
/// <summary> /// Adds the AWS logging provider to the log builder using the configuration specified in the AWSLoggerConfig /// </summary> /// <param name="builder"></param> /// <param name="config">Configuration on how to connect to AWS and how the log messages should be sent.</param> /// <param name="filter">A filter function that has the logger category name and log level which can be used to filter messages being sent to AWS.</param> /// <returns></returns> public static ILoggingBuilder AddAWSProvider(this ILoggingBuilder builder, AWSLoggerConfig config, Func <string, LogLevel, bool> filter) { var provider = new AWSLoggerProvider(config, filter); builder.AddProvider(provider); return(builder); }
public void ValidAppsettingsFilter() { var configSection = LoggerConfigSectionSetup("ValidAppsettingsFilter.json", null).GetSection("LogLevel"); if (!(configSection != null && configSection.GetChildren().Count() > 0)) { configSection = null; } var categoryName = typeof(TestFilter).GetTypeInfo().FullName; var coreLogger = new FakeCoreLogger(); var logger = new AWSLogger( categoryName, coreLogger, AWSLoggerProvider.CreateConfigSectionFilter(configSection, categoryName)); logger.LogTrace("trace"); logger.LogDebug("debug"); logger.LogInformation("information"); logger.LogWarning("warning"); logger.LogError("error"); logger.LogCritical("critical"); Assert.Equal(5, coreLogger.ReceivedMessages.Count); Assert.True(coreLogger.ReceivedMessages.Contains("warning\r\n")); Assert.True(coreLogger.ReceivedMessages.Contains("error\r\n")); Assert.True(coreLogger.ReceivedMessages.Contains("critical\r\n")); }
/// <summary> /// add aws logging given instance of any IAugmentingRenderer /// </summary> /// <typeparam name="TAugmenter"></typeparam> /// <param name="loggingBuilder"></param> /// <param name="configSectionInfoBlockName">config section info block name, ex. AWS.Logging or AWS</param> /// <param name="configSection">configuration root in which we are looking for the block specified by configSectionInfoBlockName</param> /// <param name="augmentedRenderer">the IAugmentingRenderer instance to use</param> /// <param name="awsLoggerConfigAction">optional aws logger reconfigurator action</param> /// <returns>same ILoggingBuilder that was passed</returns> public static ILoggingBuilder AddAwsLogging <TAugmenter>(this ILoggingBuilder loggingBuilder, IConfiguration configSection, string configSectionInfoBlockName, TAugmenter augmentedRenderer, Action <AWSLoggerConfig> awsLoggerConfigAction = null) where TAugmenter : IAugmentingRenderer { if (loggingBuilder == null) { throw new ArgumentNullException(nameof(loggingBuilder)); } if (configSection == null) { throw new ArgumentNullException(nameof(configSection)); } (var awsConfig, var includeScopes) = configSection.GetAWSLoggingConfigSection(configSectionInfoBlockName).ProcessIncludeScopes(augmentedRenderer); if (awsConfig != null) { awsLoggerConfigAction?.Invoke(awsConfig.Config); var awsProvider = new AWSLoggerProvider(awsConfig); var augmentedProvider = new AugmentingLoggerProvider(awsProvider, augmentedRenderer, configSection) { IncludeScopes = includeScopes }; loggingBuilder.AddProvider(augmentedProvider); //We add the AUGMENTED provider. } //Return the same Logging Builder that was passed in return(loggingBuilder); }
public void DefaultFilterCheck() { var configSection = LoggerConfigSectionSetup("DefaultFilterCheck.json", null).GetSection("LogLevel"); if (!(configSection != null && configSection.GetChildren().Count() > 0)) { configSection = null; } var categoryName = "AWS.Log"; var coreLogger = new FakeCoreLogger(); var logger = new AWSLogger( categoryName, coreLogger, AWSLoggerProvider.CreateConfigSectionFilter(configSection, categoryName)); logger.LogTrace("trace"); logger.LogDebug("debug"); logger.LogInformation("information"); logger.LogWarning("warning"); logger.LogError("error"); logger.LogCritical("critical"); Assert.Equal(5, coreLogger.ReceivedMessages.Count); Assert.True(coreLogger.ReceivedMessages.Contains("warning")); Assert.True(coreLogger.ReceivedMessages.Contains("error")); Assert.True(coreLogger.ReceivedMessages.Contains("critical")); }
public void MissingLogLevelCheck() { var configSection = LoggerConfigSectionSetup("MissingLogLevelCheck.json", null).GetSection("LogLevel"); if (!(configSection != null && configSection.GetChildren().Count() > 0)) { configSection = null; } var categoryName = typeof(TestFilter).GetTypeInfo().FullName; var coreLogger = new FakeCoreLogger(); var logger = new AWSLogger( categoryName, coreLogger, AWSLoggerProvider.CreateConfigSectionFilter(configSection, categoryName)); logger.LogTrace("trace"); logger.LogDebug("debug"); logger.LogInformation("information"); logger.LogWarning("warning"); logger.LogError("error"); logger.LogCritical("critical"); Assert.Equal(6, coreLogger.ReceivedMessages.Count); Assert.Contains($"[Warning] AWS.Logger.AspNetCore.Tests.TestFilter: warning{Environment.NewLine}", coreLogger.ReceivedMessages); Assert.Contains($"[Error] AWS.Logger.AspNetCore.Tests.TestFilter: error{Environment.NewLine}", coreLogger.ReceivedMessages); Assert.Contains($"[Critical] AWS.Logger.AspNetCore.Tests.TestFilter: critical{Environment.NewLine}", coreLogger.ReceivedMessages); }
/// <summary> /// Adds the AWS logging provider to the log factory using the configuration specified in the AWSLoggerConfig /// </summary> /// <param name="factory"></param> /// <param name="config">Configuration on how to connect to AWS and how the log messages should be sent.</param> /// <param name="minLevel">The minimum log level for messages to be written.</param> /// <returns></returns> public static ILoggerFactory AddAWSProvider(this ILoggerFactory factory, IAmazonCloudWatchLogs client, AWSLoggerConfig config, LogLevel minLevel) { var provider = new AWSLoggerProvider(client, config, minLevel); factory.AddProvider(provider); return(factory); }
/// <summary> /// Adds the AWS logging provider to the log builder using the configuration specified in the AWSLoggerConfig /// </summary> /// <param name="builder"></param> /// <param name="configSection">Configuration and loglevels on how to connect to AWS and how the log messages should be sent.</param> /// <param name="formatter">A custom formatter which accepts a LogLevel, a state, and an exception and returns the formatted log message.</param> /// <returns></returns> public static ILoggingBuilder AddAWSProvider(this ILoggingBuilder builder, AWSLoggerConfigSection configSection, Func <LogLevel, object, Exception, string> formatter = null) { // If configSection is null. Assuming the logger is being activated in a debug environment // and skip adding the provider. We don't want to prevent developers running their application // locally because they don't have access or want to use AWS for their local development. if (configSection == null) { return(builder); } var provider = new AWSLoggerProvider(configSection, formatter); builder.AddProvider(provider); return(builder); }
/// <summary> /// Adds the AWS logging provider to the log factory using the configuration specified in the AWSLoggerConfig /// </summary> /// <param name="factory"></param> /// <param name="configSection">Configuration and loglevels on how to connect to AWS and how the log messages should be sent.</param> /// <param name="formatter">A custom formatter which accepts a LogLevel, a state, and an exception and returns the formatted log message.</param> /// <returns></returns> public static ILoggerFactory AddAWSProvider(this ILoggerFactory factory, AWSLoggerConfigSection configSection, Func <LogLevel, object, Exception, string> formatter = null) { // If configSection is null. Assuming the logger is being activated in a debug environment // and skip adding the provider. We don't want to prevent developers running their application // locally because they don't have access or want to use AWS for their local development. if (configSection == null) { factory.CreateLogger("AWS.Logging.AspNetCore").LogWarning("AWSLoggerConfigSection is null. LogGroup is likely not configured in config files. Skipping adding AWS Logging provider."); return(factory); } var provider = new AWSLoggerProvider(configSection, formatter); factory.AddProvider(provider); return(factory); }
/// <summary> /// Adds the AWS logging provider to the log factory using the configuration specified in the AWSLoggerConfig /// </summary> /// <param name="factory"></param> /// <param name="config">Configuration on how to connect to AWS and how the log messages should be sent.</param> /// <returns></returns> public static ILoggerFactory AddAWSProvider(this ILoggerFactory factory, AWSLoggerConfig config) { // If config is null. Assuming the logger is being activated in a debug environment // and skip adding the provider. We don't want to prevent developers running their application // locally because they don't have access or want to use AWS for their local development. if (config == null) { factory.CreateLogger("AWS.Logging.AspNetCore").LogWarning("AWSLoggerConfig is null, skipping adding AWS Logging provider."); return(factory); } var provider = new AWSLoggerProvider(config); factory.AddProvider(provider); return(factory); }
public void FilterLogLevel() { var coreLogger = new FakeCoreLogger(); var logger = new AWSLogger("FilterLogLevel", coreLogger, AWSLoggerProvider.CreateLogLevelFilter(LogLevel.Warning)); logger.LogTrace("trace"); logger.LogDebug("debug"); logger.LogInformation("information"); logger.LogWarning("warning"); logger.LogError("error"); logger.LogCritical("critical"); Assert.Equal(3, coreLogger.ReceivedMessages.Count); Assert.True(coreLogger.ReceivedMessages.Contains("warning\r\n")); Assert.True(coreLogger.ReceivedMessages.Contains("error\r\n")); Assert.True(coreLogger.ReceivedMessages.Contains("critical\r\n")); }
public void FilterLogLevel() { var coreLogger = new FakeCoreLogger(); var logger = new AWSLogger("FilterLogLevel", coreLogger, AWSLoggerProvider.CreateLogLevelFilter(LogLevel.Warning)); logger.LogTrace("trace"); logger.LogDebug("debug"); logger.LogInformation("information"); logger.LogWarning("warning"); logger.LogError("error"); logger.LogCritical("critical"); Assert.Equal(3, coreLogger.ReceivedMessages.Count); Assert.Contains($"[Warning] FilterLogLevel: warning{Environment.NewLine}", coreLogger.ReceivedMessages); Assert.Contains($"[Error] FilterLogLevel: error{Environment.NewLine}", coreLogger.ReceivedMessages); Assert.Contains($"[Critical] FilterLogLevel: critical{Environment.NewLine}", coreLogger.ReceivedMessages); }