forked from BedeGaming/sinks-rollingfile
-
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.
Refactored for Cross Platform support. Currently only .NET 4.5 implem…
…entation as before, but now as PCL projec is used to contain core code, should be very easy to add in MonoDroid and MonoTouch and other platforms. Closes BedeGaming#9
- Loading branch information
Showing
22 changed files
with
383 additions
and
79 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
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
21 changes: 21 additions & 0 deletions
21
src/Serilog.Sinks.RollingFileAlternate.Portable/Constants.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,21 @@ | ||
namespace Serilog.Sinks.RollingFileAlternate | ||
{ | ||
/// <summary> | ||
/// Commonly used Constants. | ||
/// </summary> | ||
public class Constants | ||
{ | ||
|
||
/// <summary> | ||
/// The default output template used for log messages. | ||
/// </summary> | ||
public const string DefaultOutputTemplate = | ||
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"; | ||
|
||
/// <summary> | ||
/// The size of 2 megebytes in bytes. | ||
/// </summary> | ||
public const long TwoMegabytes = 1024 * 1024 * 2; | ||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Serilog.Sinks.RollingFileAlternate.Portable/IFileSystem.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,37 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace Serilog.Sinks.RollingFileAlternate | ||
{ | ||
/// <summary> | ||
/// Provides file system access. | ||
/// </summary> | ||
public interface IFileSystem | ||
{ | ||
/// <summary> | ||
/// Returns whether the specified directory exists. | ||
/// </summary> | ||
/// <returns></returns> | ||
bool DirectoryExists(string path); | ||
|
||
/// <summary> | ||
/// Creates the specified directory. | ||
/// </summary> | ||
/// <param name="path"></param> | ||
void CreateDirectory(string path); | ||
|
||
/// <summary> | ||
/// Opens the specified file in the mode necessary to append information only. | ||
/// </summary> | ||
/// <param name="fullPath"></param> | ||
/// <returns></returns> | ||
Stream OpenFileForAppend(string fullPath); | ||
|
||
/// <summary> | ||
/// Returns the names of the files in the specified directory. | ||
/// </summary> | ||
/// <param name="directory"></param> | ||
/// <returns></returns> | ||
IEnumerable<string> GetFiles(string directory); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/Serilog.Sinks.RollingFileAlternate.Portable/LoggerConfigurationExtensions.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,76 @@ | ||
using System; | ||
using Serilog.Configuration; | ||
using Serilog.Events; | ||
using Serilog.Formatting.Display; | ||
using Serilog.Sinks.RollingFileAlternate.Sinks.HourlyRolling; | ||
using Serilog.Sinks.RollingFileAlternate.Sinks.SizeRollingFileSink; | ||
|
||
namespace Serilog.Sinks.RollingFileAlternate | ||
{ | ||
/// <summary> | ||
/// Configuration extensions to be able to use fluent syntax for constructing | ||
/// a file sink that rolls files based on size. | ||
/// </summary> | ||
public static class LoggerConfigurationExtensions | ||
{ | ||
|
||
/// <summary> | ||
/// Creates an alternative implementation of the rolling file sink | ||
/// that rolls files based on their size. | ||
/// </summary> | ||
/// <param name="configuration"><see cref="LoggerSinkConfiguration"/></param> | ||
/// <param name="fileSystem">Provides access to the file system.</param> | ||
/// <param name="logDirectory">The names of the directory to be logged</param> | ||
/// <param name="minimumLevel">Minimum <see cref="LogEventLevel"/></param> | ||
/// <param name="outputTemplate">The template for substituting logged parameters</param> | ||
/// <param name="formatProvider">A culture specific format provider</param> | ||
/// <param name="fileSizeLimitBytes">The size files should grow up to (default 2MB)</param> | ||
/// <returns></returns> | ||
public static LoggerConfiguration RollingFileAlternate( | ||
this LoggerSinkConfiguration configuration, | ||
IFileSystem fileSystem, | ||
string logDirectory, | ||
LogEventLevel minimumLevel = LevelAlias.Minimum, | ||
string outputTemplate = Constants.DefaultOutputTemplate, | ||
IFormatProvider formatProvider = null, | ||
long? fileSizeLimitBytes = null) | ||
{ | ||
if (configuration == null) | ||
{ | ||
throw new ArgumentNullException("configuration"); | ||
} | ||
|
||
var templateFormatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); | ||
var sink = new AlternateRollingFileSink(logDirectory, templateFormatter, fileSizeLimitBytes ?? Constants.TwoMegabytes, fileSystem); | ||
return configuration.Sink(sink, minimumLevel); | ||
} | ||
|
||
/// <summary> | ||
/// Creates an hourly rolling file sink that rolls files every hour. | ||
/// </summary> | ||
/// <param name="configuration"><see cref="LoggerSinkConfiguration"/></param> | ||
/// <param name="fileSystem">Provides access to the file system.</param> | ||
/// <param name="logDirectory">The names of the directory to be logged</param> | ||
/// <param name="minimumLevel">Minimum <see cref="LogEventLevel"/></param> | ||
/// <param name="outputTemplate">The template for substituting logged parameters</param> | ||
/// <param name="formatProvider">A culture specific format provider</param> | ||
/// <returns></returns> | ||
public static LoggerConfiguration HourlyRollingFileAlternate( | ||
this LoggerSinkConfiguration configuration, | ||
IFileSystem fileSystem, | ||
string logDirectory, | ||
LogEventLevel minimumLevel = LevelAlias.Minimum, | ||
string outputTemplate = Constants.DefaultOutputTemplate, | ||
IFormatProvider formatProvider = null) | ||
{ | ||
if (configuration == null) | ||
{ | ||
throw new ArgumentNullException("configuration"); | ||
} | ||
|
||
var templateFormatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); | ||
var sink = new HourlyRollingFileSink(logDirectory, templateFormatter, fileSystem); | ||
return configuration.Sink(sink, minimumLevel); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Serilog.Sinks.RollingFileAlternate.Portable/Properties/AssemblyInfo.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,13 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyTitle("Serilog.Sinks.RollingFileAlternate.Portable")] | ||
[assembly: AssemblyDescription("Serilog sink for RollingFile")] | ||
[assembly: AssemblyCopyright("Copyright © Serilog Contributors 2014")] | ||
|
||
[assembly: InternalsVisibleTo("Serilog.Sinks.RollingFileAlternate.Tests," + | ||
"PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + | ||
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + | ||
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + | ||
"94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + | ||
"b19485ec")] |
76 changes: 76 additions & 0 deletions
76
...og.Sinks.RollingFileAlternate.Portable/Serilog.Sinks.RollingFileAlternate.Portable.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,76 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{D0129A92-AD43-4CE7-9090-4A5DF073995B}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Serilog.Sinks.RollingFileAlternate</RootNamespace> | ||
<AssemblyName>Serilog.Sinks.RollingFileAlternate.Portable</AssemblyName> | ||
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile> | ||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</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> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<DocumentationFile>bin\Debug\Serilog.Sinks.RollingFileAlternate.Portable.xml</DocumentationFile> | ||
</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> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SignAssembly>true</SignAssembly> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<AssemblyOriginatorKeyFile>..\..\assets\Serilog.snk</AssemblyOriginatorKeyFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Serilog, Version=1.5.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\packages\Serilog.1.5.7\lib\net45\Serilog.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Serilog.FullNetFx, Version=1.5.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\packages\Serilog.1.5.7\lib\net45\Serilog.FullNetFx.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Constants.cs" /> | ||
<Compile Include="IFileSystem.cs" /> | ||
<Compile Include="LoggerConfigurationExtensions.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Sinks\HourlyRolling\HourlyRollingFileSink.cs" /> | ||
<Compile Include="Sinks\HourlyRolling\HourlyFileSink.cs" /> | ||
<Compile Include="Sinks\HourlyRolling\HourlyLogFileDescription.cs" /> | ||
<Compile Include="Sinks\SizeRollingFileSink\LogFileInfo.cs" /> | ||
<Compile Include="Sinks\SizeRollingFileSink\SizeLimitedFileSink.cs" /> | ||
<Compile Include="Sinks\SizeRollingFileSink\SizeLimitedLogFileDescription.cs" /> | ||
<Compile Include="Sinks\SizeRollingFileSink\AlternateRollingFileSink.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.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> |
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
6 changes: 3 additions & 3 deletions
6
...HourlyRolling/HourlyLogFileDescription.cs → ...HourlyRolling/HourlyLogFileDescription.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
Oops, something went wrong.