Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nberardi/serilog into nbe…
Browse files Browse the repository at this point in the history
…rardi-master

Conflicts:
	Serilog.sln
	src/Serilog/Policies/NullableScalarConversionPolicy.cs
	src/Serilog/Serilog.nuspec
  • Loading branch information
nblumhardt committed Jan 22, 2015
1 parent e58ada5 commit 86bcdab
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Serilog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.AzureEventHub
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Serilog.Extras.FSharp", "src\Serilog.Extras.FSharp\Serilog.Extras.FSharp.fsproj", "{088A4030-7C7A-4434-964A-8E9E42DB17F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.MonoAndroid", "src\Serilog.Sinks.MonoAndroid\Serilog.Sinks.MonoAndroid.csproj", "{129D844D-273B-4E51-904B-2BD8169427DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.MonoTouch", "src\Serilog.Sinks.MonoTouch\Serilog.Sinks.MonoTouch.csproj", "{7E96D14B-2224-4EB9-B26B-6306D225024F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -286,6 +290,14 @@ Global
{088A4030-7C7A-4434-964A-8E9E42DB17F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{088A4030-7C7A-4434-964A-8E9E42DB17F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{088A4030-7C7A-4434-964A-8E9E42DB17F0}.Release|Any CPU.Build.0 = Release|Any CPU
{129D844D-273B-4E51-904B-2BD8169427DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{129D844D-273B-4E51-904B-2BD8169427DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{129D844D-273B-4E51-904B-2BD8169427DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{129D844D-273B-4E51-904B-2BD8169427DF}.Release|Any CPU.Build.0 = Release|Any CPU
{7E96D14B-2224-4EB9-B26B-6306D225024F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E96D14B-2224-4EB9-B26B-6306D225024F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E96D14B-2224-4EB9-B26B-6306D225024F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E96D14B-2224-4EB9-B26B-6306D225024F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -335,5 +347,7 @@ Global
{B2548173-2772-4710-AB6E-D239F9074FFF} = {0D135C0C-A60B-454A-A2F4-CD74A30E04B0}
{F779C831-866F-4B87-B733-1BD1DB1E1606} = {037440DE-440B-4129-9F7A-09B42D00397E}
{088A4030-7C7A-4434-964A-8E9E42DB17F0} = {037440DE-440B-4129-9F7A-09B42D00397E}
{129D844D-273B-4E51-904B-2BD8169427DF} = {037440DE-440B-4129-9F7A-09B42D00397E}
{7E96D14B-2224-4EB9-B26B-6306D225024F} = {037440DE-440B-4129-9F7A-09B42D00397E}
EndGlobalSection
EndGlobal
35 changes: 35 additions & 0 deletions src/Serilog.Sinks.MonoAndroid/Enrichers/AndroidLogTagEnricher.cs
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);
}
}
}
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);
}
}
}
14 changes: 14 additions & 0 deletions src/Serilog.Sinks.MonoAndroid/Properties/AssemblyInfo.cs
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 src/Serilog.Sinks.MonoAndroid/Serilog.Sinks.MonoAndroid.csproj
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 src/Serilog.Sinks.MonoAndroid/Serilog.Sinks.MonoAndroid.nuspec
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 src/Serilog.Sinks.MonoAndroid/Sinks/MonoAndroid/AndroidLogSink.cs
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;
}
}
}
}
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);
}
}
}

14 changes: 14 additions & 0 deletions src/Serilog.Sinks.MonoTouch/Properties/AssemblyInfo.cs
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 src/Serilog.Sinks.MonoTouch/Serilog.Sinks.MonoTouch.csproj
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>
Loading

0 comments on commit 86bcdab

Please sign in to comment.