diff --git a/Source/Platforms/Log4net/BufferingExceptionlessAppender.cs b/Source/Platforms/Log4net/BufferingExceptionlessAppender.cs new file mode 100644 index 00000000..10afe843 --- /dev/null +++ b/Source/Platforms/Log4net/BufferingExceptionlessAppender.cs @@ -0,0 +1,39 @@ +using System; +using log4net.Appender; +using log4net.Core; + +namespace Exceptionless.Log4net { + public class BufferingExceptionlessAppender : BufferingAppenderSkeleton { + private ExceptionlessClient _client = ExceptionlessClient.Default; + + public string ApiKey { get; set; } + public string ServerUrl { get; set; } + + protected override void SendBuffer(LoggingEvent[] events) { + foreach (var e in events) { + _client.SubmitFromLogEvent(e); + } + } + + public override void ActivateOptions() { + base.ActivateOptions(); + if (!String.IsNullOrEmpty(ApiKey) || !String.IsNullOrEmpty(ServerUrl)) + _client = new ExceptionlessClient(config => + { + if (!String.IsNullOrEmpty(ApiKey)) + config.ApiKey = ApiKey; + if (!String.IsNullOrEmpty(ServerUrl)) + config.ServerUrl = ServerUrl; + config.UseInMemoryStorage(); + }); + } + + protected override void Append(LoggingEvent loggingEvent) + { + if (!_client.Configuration.IsValid) + return; + + base.Append(loggingEvent); + } + } +} \ No newline at end of file diff --git a/Source/Platforms/Log4net/Exceptionless.Log4net.csproj b/Source/Platforms/Log4net/Exceptionless.Log4net.csproj index 0ab71643..3a730eaf 100644 --- a/Source/Platforms/Log4net/Exceptionless.Log4net.csproj +++ b/Source/Platforms/Log4net/Exceptionless.Log4net.csproj @@ -47,6 +47,7 @@ Properties\GlobalAssemblyInfo.cs +