Skip to content

Commit 6a05b4a

Browse files
committed
Added a log4net appender.
1 parent 3715b26 commit 6a05b4a

11 files changed

+270
-32
lines changed

Exceptionless.Net.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exceptionless.NLog", "Sourc
5757
EndProject
5858
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exceptionless", "Source\Platforms\Console\Exceptionless.csproj", "{1E53D5CD-1719-4BFB-A9A8-7D46BACA6402}"
5959
EndProject
60+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exceptionless.Log4net", "Source\Platforms\Log4net\Exceptionless.Log4net.csproj", "{C3411D82-A4C9-41AF-99B8-F71926D69FD1}"
61+
EndProject
6062
Global
6163
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6264
Debug|Any CPU = Debug|Any CPU
@@ -257,6 +259,16 @@ Global
257259
{1E53D5CD-1719-4BFB-A9A8-7D46BACA6402}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
258260
{1E53D5CD-1719-4BFB-A9A8-7D46BACA6402}.Release|Mixed Platforms.Build.0 = Release|Any CPU
259261
{1E53D5CD-1719-4BFB-A9A8-7D46BACA6402}.Release|x86.ActiveCfg = Release|Any CPU
262+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
263+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
264+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
265+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
266+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Debug|x86.ActiveCfg = Debug|Any CPU
267+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
268+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Release|Any CPU.Build.0 = Release|Any CPU
269+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
270+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
271+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1}.Release|x86.ActiveCfg = Release|Any CPU
260272
EndGlobalSection
261273
GlobalSection(SolutionProperties) = preSolution
262274
HideSolutionNode = FALSE
@@ -278,5 +290,6 @@ Global
278290
{34FE8E6E-247B-46DD-967E-46E45D1CAE6D} = {DAA02D3B-8404-4938-AB04-84AC31C1AD45}
279291
{5EB81EEF-ED35-4AD2-9B20-0B3E5C94BBA4} = {AD891FB6-E07A-47DB-AA64-B68AA8DEB7CA}
280292
{1E53D5CD-1719-4BFB-A9A8-7D46BACA6402} = {AD891FB6-E07A-47DB-AA64-B68AA8DEB7CA}
293+
{C3411D82-A4C9-41AF-99B8-F71926D69FD1} = {AD891FB6-E07A-47DB-AA64-B68AA8DEB7CA}
281294
EndGlobalSection
282295
EndGlobal
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{C3411D82-A4C9-41AF-99B8-F71926D69FD1}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Exceptionless.NLog</RootNamespace>
11+
<AssemblyName>Exceptionless.NLog</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
<DocumentationFile>bin\Release\$(TargetFrameworkVersion)\Exceptionless.NLog.xml</DocumentationFile>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="log4net">
35+
<HintPath>..\..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
36+
</Reference>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="..\..\GlobalAssemblyInfo.cs">
47+
<Link>Properties\GlobalAssemblyInfo.cs</Link>
48+
</Compile>
49+
<Compile Include="ExceptionlessAppender.cs" />
50+
<Compile Include="ExceptionlessClientExtensions.cs" />
51+
<Compile Include="Log4netExceptionlessLog.cs" />
52+
<Compile Include="Properties\AssemblyInfo.cs" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<ProjectReference Include="..\..\Shared\Exceptionless.Portable.csproj">
56+
<Project>{14dfd206-b445-4d52-9c3c-8b2f69b22b91}</Project>
57+
<Name>Exceptionless.Portable</Name>
58+
</ProjectReference>
59+
</ItemGroup>
60+
<ItemGroup>
61+
<None Include="NuGet\Exceptionless.Log4net.nuspec" />
62+
<None Include="NuGet\readme.txt" />
63+
<None Include="packages.config" />
64+
</ItemGroup>
65+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
66+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
67+
Other similar extension points exist, see Microsoft.Common.targets.
68+
<Target Name="BeforeBuild">
69+
</Target>
70+
<Target Name="AfterBuild">
71+
</Target>
72+
-->
73+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using log4net.Appender;
4+
using log4net.Core;
5+
6+
namespace Exceptionless.NLog {
7+
public class ExceptionlessAppender : AppenderSkeleton {
8+
private ExceptionlessClient _client;
9+
10+
public string ApiKey { get; set; }
11+
public string ServerUrl { get; set; }
12+
13+
public override void ActivateOptions() {
14+
if (!String.IsNullOrEmpty(ApiKey) || !String.IsNullOrEmpty(ServerUrl))
15+
_client = new ExceptionlessClient(config => {
16+
config.ApiKey = ApiKey;
17+
config.ServerUrl = ServerUrl;
18+
});
19+
else
20+
_client = ExceptionlessClient.Default;
21+
}
22+
23+
protected override void Append(LoggingEvent loggingEvent) {
24+
if (!_client.Configuration.IsValid)
25+
return;
26+
27+
_client.SubmitFromLogEvent(loggingEvent);
28+
}
29+
}
30+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using log4net.Core;
5+
6+
namespace Exceptionless.NLog {
7+
public static class ExceptionlessClientExtensions {
8+
public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, LoggingEvent ev) {
9+
var builder = ev.ExceptionObject != null ? client.CreateException(ev.ExceptionObject) : client.CreateLog(ev.LoggerName, ev.RenderedMessage, ev.Level.Name);
10+
builder.Target.Date = ev.TimeStamp;
11+
12+
if (!String.IsNullOrWhiteSpace(ev.RenderedMessage))
13+
builder.SetMessage(ev.RenderedMessage);
14+
15+
if (ev.ExceptionObject != null)
16+
builder.SetSource(ev.LoggerName);
17+
18+
var props = ev.GetProperties();
19+
foreach (var key in props.GetKeys().Where(key => !_ignoredEventProperties.Contains(key, StringComparer.OrdinalIgnoreCase)))
20+
builder.SetProperty(key, props[key]);
21+
22+
return builder;
23+
}
24+
25+
public static void SubmitFromLogEvent(this ExceptionlessClient client, LoggingEvent ev) {
26+
CreateFromLogEvent(client, ev).Submit();
27+
}
28+
29+
private static readonly List<string> _ignoredEventProperties = new List<string> {
30+
"CallerFilePath",
31+
"CallerMemberName",
32+
"CallerLineNumber"
33+
};
34+
}
35+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using Exceptionless.Logging;
3+
using log4net;
4+
5+
namespace Exceptionless.NLog {
6+
public class Log4netExceptionlessLog : IExceptionlessLog {
7+
// ignore and let NLog determine what should be captured.
8+
public LogLevel MinimumLogLevel { get; set; }
9+
10+
public void Error(string message, string source = null, Exception exception = null) {
11+
LogManager.GetLogger(source ?? "Exceptionless").Error(message, exception);
12+
}
13+
14+
public void Info(string message, string source = null) {
15+
LogManager.GetLogger(source ?? "Exceptionless").Info(message);
16+
}
17+
18+
public void Debug(string message, string source = null) {
19+
LogManager.GetLogger(source ?? "Exceptionless").Debug(message);
20+
}
21+
22+
public void Warn(string message, string source = null) {
23+
LogManager.GetLogger(source ?? "Exceptionless").Warn(message);
24+
}
25+
26+
public void Trace(string message, string source = null) {
27+
LogManager.GetLogger(source ?? "Exceptionless").Debug(message);
28+
}
29+
30+
public void Flush() { }
31+
}
32+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<package>
3+
<metadata>
4+
<id>Exceptionless.Log4net</id>
5+
<version>$version$</version>
6+
<authors>Exceptionless</authors>
7+
<owners>Exceptionless</owners>
8+
<description>Log4net target that sends log entries to Exceptionless. Exceptionless is a cloud based error reporting service that sends your exceptions to http://exceptionless.io and provides aggregated views and analytics.</description>
9+
<projectUrl>http://exceptionless.io</projectUrl>
10+
<iconUrl>https://be.exceptionless.io/img/exceptionless-32.png</iconUrl>
11+
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
12+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
13+
<releaseNotes>http://exceptionless.io/category/versions/</releaseNotes>
14+
<tags>NLog Target Exceptionless Error Report Reporting Exception Logging Log ELMAH</tags>
15+
<dependencies>
16+
<dependency id="Exceptionless.Portable" version="[$version$]" />
17+
<dependency id="log4net" version="2.0.3" />
18+
</dependencies>
19+
</metadata>
20+
</package>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-------------------------------------
2+
Exceptionless Readme
3+
-------------------------------------
4+
Exceptionless provides real-time error reporting for your apps. It organizes the
5+
gathered information into simple actionable data that will help your app become
6+
exceptionless!
7+
8+
Learn more at http://exceptionless.io.
9+
10+
-------------------------------------
11+
How to get an api key
12+
-------------------------------------
13+
The Exceptionless client requires an api key to use the Exceptionless service.
14+
You can get your Exceptionless api key by logging into http://exceptionless.io
15+
and viewing your project configuration page.
16+
17+
-------------------------------------
18+
log4net Integration
19+
-------------------------------------
20+
21+
Here is an example log.config file that shows how to use the Exceptionless NLog target.
22+
23+
...
24+
25+
-------------------------------------
26+
Documentation and Support
27+
-------------------------------------
28+
Please visit http://exceptionless.io for documentation and support.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#region Copyright 2014 Exceptionless
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
8+
#endregion
9+
10+
using System;
11+
using System.Reflection;
12+
using System.Runtime.InteropServices;
13+
14+
[assembly: CLSCompliant(true)]
15+
[assembly: AssemblyTitle("Exceptionless.Log4net")]
16+
[assembly: AssemblyDescription("Exceptionless Log4net")]
17+
[assembly: ComVisible(false)]
18+
[assembly: Guid("ff5a0dc6-4382-457f-8ec3-d7b576865922")]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="log4net" version="2.0.3" targetFramework="net451" />
4+
</packages>

Source/Platforms/NLog/Exceptionless.NLog.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
<Reference Include="System.Xml" />
4444
</ItemGroup>
4545
<ItemGroup>
46+
<Compile Include="..\..\GlobalAssemblyInfo.cs">
47+
<Link>Properties\GlobalAssemblyInfo.cs</Link>
48+
</Compile>
4649
<Compile Include="ExceptionlessField.cs" />
4750
<Compile Include="ExceptionlessTarget.cs" />
4851
<Compile Include="ExceptionlessClientExtensions.cs" />

0 commit comments

Comments
 (0)