forked from serilog/serilog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/nberardi/serilog into nbe…
…rardi-master Conflicts: Serilog.sln src/Serilog/Policies/NullableScalarConversionPolicy.cs src/Serilog/Serilog.nuspec
- Loading branch information
1 parent
e58ada5
commit 86bcdab
Showing
12 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Serilog.Sinks.MonoAndroid/Enrichers/AndroidLogTagEnricher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Linq; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Enrichers | ||
{ | ||
public class AndroidLogTagEnricher : ILogEventEnricher | ||
{ | ||
private LogEventProperty _cachedProperty; | ||
|
||
/// <summary> | ||
/// The property name added to enriched log events. | ||
/// </summary> | ||
public const string TagPropertyName = "Tag"; | ||
|
||
public readonly string TagPropertyValue; | ||
|
||
public AndroidLogTagEnricher(string tag) | ||
{ | ||
TagPropertyValue = tag ?? ""; | ||
} | ||
|
||
/// <summary> | ||
/// Enrich the log event. | ||
/// </summary> | ||
/// <param name="logEvent">The log event to enrich.</param> | ||
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param> | ||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) | ||
{ | ||
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(TagPropertyName, TagPropertyValue); | ||
logEvent.AddPropertyIfAbsent(_cachedProperty); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Serilog.Sinks.MonoAndroid/LoggerConfigurationMonoAndroidExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using Serilog.Configuration; | ||
using Serilog.Events; | ||
using Serilog.Formatting.Display; | ||
using Serilog.Sinks.MonoAndroid; | ||
|
||
namespace Serilog | ||
{ | ||
public static class LoggerConfigurationMonoAndroidExtensions | ||
{ | ||
private const string DefaultAndroidLogOutputTemplate = "[{Level}] {Message:l{NewLine:l}{Exception:l}"; | ||
|
||
public static LoggerConfiguration AndroidLog(this LoggerSinkConfiguration sinkConfiguration, | ||
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, | ||
string outputTemplate = DefaultAndroidLogOutputTemplate, | ||
IFormatProvider formatProvider = null) | ||
{ | ||
|
||
if (sinkConfiguration == null) | ||
throw new ArgumentNullException("sinkConfiguration"); | ||
|
||
if (outputTemplate == null) | ||
throw new ArgumentNullException("outputTemplate"); | ||
|
||
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); | ||
return sinkConfiguration.Sink(new AndroidLogSink(formatter), restrictedToMinimumLevel); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyTitle("Serilog.Sinks.MonoAndroid")] | ||
[assembly: AssemblyDescription("Serilog sink for MonoAndroid")] | ||
[assembly: AssemblyCopyright("Copyright © Serilog Contributors 2014")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] | ||
|
||
[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + | ||
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + | ||
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + | ||
"94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + | ||
"b19485ec")] |
69 changes: 69 additions & 0 deletions
69
src/Serilog.Sinks.MonoAndroid/Serilog.Sinks.MonoAndroid.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{129D844D-273B-4E51-904B-2BD8169427DF}</ProjectGuid> | ||
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Serilog</RootNamespace> | ||
<AssemblyName>Serilog.Sinks.MonoAndroid</AssemblyName> | ||
<FileAlignment>512</FileAlignment> | ||
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile> | ||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> | ||
<AndroidUseLatestPlatformSdk /> | ||
<TargetFrameworkVersion>v2.3</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<DocumentationFile>bin\Release\Serilog.Sinks.MonoAndroid.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Mono.Android" /> | ||
<Reference Include="mscorlib" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Enrichers\AndroidLogTagEnricher.cs" /> | ||
<Compile Include="LoggerConfigurationMonoAndroidExtensions.cs" /> | ||
<Compile Include="Sinks\MonoAndroid\AndroidLogSink.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Serilog.Sinks.MonoAndroid.nuspec"> | ||
<SubType>Designer</SubType> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Serilog\Serilog.csproj"> | ||
<Project>{0915dbd9-0f7c-4439-8d9e-74c3d579b219}</Project> | ||
<Name>Serilog</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
src/Serilog.Sinks.MonoAndroid/Serilog.Sinks.MonoAndroid.nuspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<metadata> | ||
<id>Serilog.Sinks.MonoAndroid</id> | ||
<version>0.1.0</version> | ||
<authors>Serilog Contributors</authors> | ||
<description>Serilog event sink that writes to Xamarin Android.</description> | ||
<language>en-US</language> | ||
<projectUrl>http://serilog.net</projectUrl> | ||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl> | ||
<iconUrl>http://serilog.net/images/serilog-nuget.png</iconUrl> | ||
<tags>serilog logging xamarin android monoandroid</tags> | ||
<dependencies> | ||
<dependency id="Serilog" /> | ||
<dependency id="Newtonsoft.Json" /> | ||
</dependencies> | ||
</metadata> | ||
<files> | ||
<file src="src\Serilog.Sinks.MonoAndroid\bin\iPhone\Release\Serilog.Sinks.MonoAndroid.dll" target="lib\MonoAndroid" /> | ||
<file src="src\Serilog.Sinks.MonoAndroid\bin\iPhone\Release\Serilog.Sinks.MonoAndroid.xml" target="lib\MonoAndroid" /> | ||
</files> | ||
</package> | ||
|
62 changes: 62 additions & 0 deletions
62
src/Serilog.Sinks.MonoAndroid/Sinks/MonoAndroid/AndroidLogSink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Android.Util; | ||
using Serilog.Core; | ||
using Serilog.Enrichers; | ||
using Serilog.Events; | ||
using Serilog.Formatting; | ||
using AndroidLog = Android.Util.Log; | ||
|
||
namespace Serilog.Sinks.MonoAndroid | ||
{ | ||
public class AndroidLogSink : ILogEventSink | ||
{ | ||
private readonly ITextFormatter _textFormatter; | ||
|
||
public AndroidLogSink(ITextFormatter textFormatter) | ||
{ | ||
if (textFormatter == null) throw new ArgumentNullException("textFormatter"); | ||
_textFormatter = textFormatter; | ||
} | ||
|
||
public void Emit(LogEvent logEvent) | ||
{ | ||
if (logEvent == null) throw new ArgumentNullException("logEvent"); | ||
var renderSpace = new StringWriter(); | ||
_textFormatter.Format(logEvent, renderSpace); | ||
|
||
var tag = logEvent.Properties.Where(x => x.Key == AndroidLogTagEnricher.TagPropertyName).Select(x => x.Value.ToString("l", null)).FirstOrDefault() ?? ""; | ||
|
||
switch (logEvent.Level) { | ||
case LogEventLevel.Debug: | ||
AndroidLog.Debug(tag, renderSpace.ToString()); | ||
break; | ||
|
||
case LogEventLevel.Information: | ||
AndroidLog.Info(tag, renderSpace.ToString()); | ||
break; | ||
|
||
case LogEventLevel.Verbose: | ||
AndroidLog.Verbose(tag, renderSpace.ToString()); | ||
break; | ||
|
||
case LogEventLevel.Warning: | ||
AndroidLog.Warn(tag, renderSpace.ToString()); | ||
break; | ||
|
||
case LogEventLevel.Error: | ||
AndroidLog.Error(tag, renderSpace.ToString()); | ||
break; | ||
|
||
case LogEventLevel.Fatal: | ||
AndroidLog.Wtf(tag, renderSpace.ToString()); | ||
break; | ||
|
||
default: | ||
AndroidLog.WriteLine(LogPriority.Assert, tag, renderSpace.ToString()); | ||
break; | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Serilog.Sinks.MonoTouch/LoggerConfigurationMonoTouchExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using Serilog.Configuration; | ||
using Serilog.Events; | ||
using Serilog.Formatting.Display; | ||
using Serilog.Sinks.MonoTouch; | ||
|
||
namespace Serilog | ||
{ | ||
public static class LoggerConfigurationMonoTouchExtensions | ||
{ | ||
private const string DefaultNSLogOutputTemplate = "[{Level}] {Message:l{NewLine:l}{Exception:l}"; | ||
|
||
public static LoggerConfiguration NSLog(this LoggerSinkConfiguration sinkConfiguration, | ||
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, | ||
string outputTemplate = DefaultNSLogOutputTemplate, | ||
IFormatProvider formatProvider = null) { | ||
|
||
if (sinkConfiguration == null) | ||
throw new ArgumentNullException ("sinkConfiguration"); | ||
|
||
if (outputTemplate == null) | ||
throw new ArgumentNullException ("outputTemplate"); | ||
|
||
var formatter = new MessageTemplateTextFormatter (outputTemplate, formatProvider); | ||
return sinkConfiguration.Sink (new NSLogSink (formatter), restrictedToMinimumLevel); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyTitle("Serilog.Sinks.MonoTouch")] | ||
[assembly: AssemblyDescription("Serilog sink for MonoTouch")] | ||
[assembly: AssemblyCopyright("Copyright © Serilog Contributors 2014")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] | ||
|
||
[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + | ||
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + | ||
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + | ||
"94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + | ||
"b19485ec")] |
59 changes: 59 additions & 0 deletions
59
src/Serilog.Sinks.MonoTouch/Serilog.Sinks.MonoTouch.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{7E96D14B-2224-4EB9-B26B-6306D225024F}</ProjectGuid> | ||
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>Serilog</RootNamespace> | ||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix> | ||
<AssemblyName>Serilog.Sinks.MonoTouch</AssemblyName> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\iPhone\Debug</OutputPath> | ||
<DefineConstants>DEBUG</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
<MtouchDebug>true</MtouchDebug> | ||
<CodesignKey>iPhone Developer</CodesignKey> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>none</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\iPhone\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
<CodesignKey>iPhone Developer</CodesignKey> | ||
<DocumentationFile>bin\iPhone\Release\Serilog.Sinks.MonoTouch.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Sinks\MonoTouch\NSLogSink.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="LoggerConfigurationMonoTouchExtensions.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="monotouch" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" /> | ||
<ItemGroup> | ||
<None Include="Serilog.Sinks.MonoTouch.nuspec"> | ||
<SubType>Designer</SubType> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Serilog\Serilog.csproj"> | ||
<Project>{0915dbd9-0f7c-4439-8d9e-74c3d579b219}</Project> | ||
<Name>Serilog</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.