Skip to content

Commit

Permalink
Added BufferingExceptionlessAppender
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyelton committed Apr 2, 2015
1 parent 65b2611 commit 966b1a6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Source/Platforms/Log4net/BufferingExceptionlessAppender.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
1 change: 1 addition & 0 deletions Source/Platforms/Log4net/Exceptionless.Log4net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="..\..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="BufferingExceptionlessAppender.cs" />
<Compile Include="ExceptionlessAppender.cs" />
<Compile Include="ExceptionlessClientExtensions.cs" />
<Compile Include="Log4netExceptionlessLog.cs" />
Expand Down

0 comments on commit 966b1a6

Please sign in to comment.