public static void ConfigureCloudWatchLog4net() { Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(Assembly.GetEntryAssembly()); //PatternLayout patternLayout = new PatternLayout //{ // ConversionPattern = "%-4timestamp [%thread] %-5level %logger %ndc - %message%newline" //}; var splunkLayoutCW = new SplunkLayout() { LoggedProcessId = "LogTest3Rolling.LAB", TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ", WithTimeStamp = false, }; splunkLayoutCW.ActivateOptions(); //You should be able create any appender and load it into the LogManager which //would allow you to drop the log4net.config AWSAppender cWappender = new AWSAppender { Name = "StartupLogger", Layout = splunkLayoutCW, BatchPushInterval = new TimeSpan(0, 0, 0, 5, 0), Threshold = Level.Debug, // Set log group and region. Assume credentials will be found using the default profile or IAM credentials. LogGroup = "Logging.Startup", Region = "us-east-1" }; var cwFilter = new log4net.Filter.LoggerMatchFilter() { LoggerToMatch = "LogTest3.CloudWatchFilter", AcceptOnMatch = true }; var non = new log4net.Filter.DenyAllFilter(); non.ActivateOptions(); cwFilter.ActivateOptions(); cWappender.AddFilter(cwFilter); cWappender.AddFilter(non); cWappender.ActivateOptions(); hierarchy.Root.AddAppender(cWappender); }
public static void ConfigureLog4net() { Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(Assembly.GetEntryAssembly()); var splunkLayoutS3 = new SplunkLayout() { LoggedProcessId = "LogTest3Rolling.LAB", TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ", ObjectFormat = "html", Header = "<h1>Adding a Header???</h1>", Footer = "<h3>Also a footer??? Oh la la</h3>" }; splunkLayoutS3.ActivateOptions(); var s3appender = new S3Appender() { Name = "S3NoConfigAppender", Layout = splunkLayoutS3, Threshold = Level.Debug, BufferSize = 5, LibraryLogFileName = "_Log_NoConfigError", BucketName = "logtest2bucketpoc", LogDirectory = "WhatIsThis", FilePrefix = "S3Appender_html", FileExtension = "html", }; var htmlFilter = new log4net.Filter.LoggerMatchFilter() { LoggerToMatch = "LogTest3.HtmlFilter", AcceptOnMatch = true }; var non = new log4net.Filter.DenyAllFilter(); non.ActivateOptions(); htmlFilter.ActivateOptions(); s3appender.AddFilter(htmlFilter); s3appender.AddFilter(non); s3appender.ActivateOptions(); hierarchy.Root.AddAppender(s3appender); }