Skip to content

Commit 966b1a6

Browse files
committed
Added BufferingExceptionlessAppender
1 parent 65b2611 commit 966b1a6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using log4net.Appender;
3+
using log4net.Core;
4+
5+
namespace Exceptionless.Log4net {
6+
public class BufferingExceptionlessAppender : BufferingAppenderSkeleton {
7+
private ExceptionlessClient _client = ExceptionlessClient.Default;
8+
9+
public string ApiKey { get; set; }
10+
public string ServerUrl { get; set; }
11+
12+
protected override void SendBuffer(LoggingEvent[] events) {
13+
foreach (var e in events) {
14+
_client.SubmitFromLogEvent(e);
15+
}
16+
}
17+
18+
public override void ActivateOptions() {
19+
base.ActivateOptions();
20+
if (!String.IsNullOrEmpty(ApiKey) || !String.IsNullOrEmpty(ServerUrl))
21+
_client = new ExceptionlessClient(config =>
22+
{
23+
if (!String.IsNullOrEmpty(ApiKey))
24+
config.ApiKey = ApiKey;
25+
if (!String.IsNullOrEmpty(ServerUrl))
26+
config.ServerUrl = ServerUrl;
27+
config.UseInMemoryStorage();
28+
});
29+
}
30+
31+
protected override void Append(LoggingEvent loggingEvent)
32+
{
33+
if (!_client.Configuration.IsValid)
34+
return;
35+
36+
base.Append(loggingEvent);
37+
}
38+
}
39+
}

Source/Platforms/Log4net/Exceptionless.Log4net.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<Compile Include="..\..\GlobalAssemblyInfo.cs">
4848
<Link>Properties\GlobalAssemblyInfo.cs</Link>
4949
</Compile>
50+
<Compile Include="BufferingExceptionlessAppender.cs" />
5051
<Compile Include="ExceptionlessAppender.cs" />
5152
<Compile Include="ExceptionlessClientExtensions.cs" />
5253
<Compile Include="Log4netExceptionlessLog.cs" />

0 commit comments

Comments
 (0)