Skip to content

Commit

Permalink
Moved IO Sinks to new projects. Dependencies required a combined commit
Browse files Browse the repository at this point in the history
  • Loading branch information
merbla committed Jan 21, 2016
1 parent b3d9701 commit 0d49b19
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 172 deletions.
14 changes: 14 additions & 0 deletions Serilog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{9EC69873
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.DiagnosticTrace", "src\Serilog.Sinks.DiagnosticTrace\Serilog.Sinks.DiagnosticTrace.xproj", "{8849C92D-2120-4C82-8226-22DF40195237}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.IOFile", "src\Serilog.Sinks.IOFile\Serilog.Sinks.IOFile.xproj", "{57E0ED0E-0F45-48AB-A73D-6A92B7C32095}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.RollingFile", "src\Serilog.Sinks.RollingFile\Serilog.Sinks.RollingFile.xproj", "{A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -49,6 +53,14 @@ Global
{8849C92D-2120-4C82-8226-22DF40195237}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8849C92D-2120-4C82-8226-22DF40195237}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8849C92D-2120-4C82-8226-22DF40195237}.Release|Any CPU.Build.0 = Release|Any CPU
{57E0ED0E-0F45-48AB-A73D-6A92B7C32095}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57E0ED0E-0F45-48AB-A73D-6A92B7C32095}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57E0ED0E-0F45-48AB-A73D-6A92B7C32095}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57E0ED0E-0F45-48AB-A73D-6A92B7C32095}.Release|Any CPU.Build.0 = Release|Any CPU
{A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -59,5 +71,7 @@ Global
{866A028E-27DB-49A0-AC78-E5FEF247C099} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
{9EC69873-5A97-4C25-AB5A-31DDE589B2D9} = {037440DE-440B-4129-9F7A-09B42D00397E}
{8849C92D-2120-4C82-8226-22DF40195237} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
{57E0ED0E-0F45-48AB-A73D-6A92B7C32095} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
{A3E6E5B4-995F-4C3D-9673-A4B6000F4E21} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
EndGlobalSection
EndGlobal
74 changes: 74 additions & 0 deletions src/Serilog.Sinks.IOFile/IOFileConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2013-2016 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Formatting.Display;
using Serilog.Sinks.IOFile;

namespace Serilog
{
public static class IOFileConfigurationExtensions
{
/// <summary>
/// Write log events to the specified file.
/// </summary>
/// <param name="sinkConfiguration">Logger sink configuration.</param>
/// <param name="path">Path to the file.</param>
/// <param name="restrictedToMinimumLevel">The minimum level for
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
/// to be changed at runtime.</param>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
/// <param name="fileSizeLimitBytes">The maximum size, in bytes, to which a log file will be allowed to grow.
/// For unrestricted growth, pass null. The default is 1 GB.</param>
/// <returns>Configuration object allowing method chaining.</returns>
/// <remarks>The file will be written using the UTF-8 character set.</remarks>
public static LoggerConfiguration File(
this LoggerSinkConfiguration sinkConfiguration,
string path,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = LoggerConfigurationFullNetFxExtensions.DefaultOutputTemplate,
IFormatProvider formatProvider = null,
long? fileSizeLimitBytes = LoggerConfigurationFullNetFxExtensions.DefaultFileSizeLimitBytes,
LoggingLevelSwitch levelSwitch = null)
{
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);

FileSink sink;
try
{
sink = new FileSink(path, formatter, fileSizeLimitBytes);
}
catch (ArgumentException)
{
throw;
}
catch (Exception ex)
{
SelfLog.WriteLine("Unable to open file sink for {0}: {1}", path, ex);
return sinkConfiguration.Sink(new NullSink());
}

return sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch);
}
}
}
11 changes: 11 additions & 0 deletions src/Serilog.Sinks.IOFile/Properties/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyVersion("2.0.0.0")]

[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=" +
"0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" +
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" +
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" +
"94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" +
"b19485ec")]
18 changes: 18 additions & 0 deletions src/Serilog.Sinks.IOFile/Serilog.Sinks.IOFile.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>57e0ed0e-0f45-48ab-a73d-6a92b7c32095</ProjectGuid>
<RootNamespace>Serilog</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2015 Serilog Contributors
// Copyright 2013-2016 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if FILE_IO

using System;
using System.IO;
using System.Text;
Expand Down Expand Up @@ -73,5 +71,4 @@ public override void Write(char[] buffer, int index, int count)

public override void Flush() => _outputWriter.Flush();
}
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2015 Serilog Contributors
// Copyright 2013-2016 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,10 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if FILE_IO

using System;
using System.IO;
using System.IO;
using System.Text;
using Serilog.Core;
using Serilog.Debugging;
Expand Down Expand Up @@ -103,5 +101,4 @@ public void Emit(LogEvent logEvent)
/// </summary>
public void Dispose() => _output.Dispose();
}
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2015 Serilog Contributors
// Copyright 2013-2016 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if FILE_IO

using Serilog.Core;
using Serilog.Events;

Expand All @@ -29,5 +27,4 @@ public void Emit(LogEvent logEvent)
{
}
}
}
#endif
}
28 changes: 28 additions & 0 deletions src/Serilog.Sinks.IOFile/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"version": "2.0.0-beta-*",
"description": "The file sink for Serilog - Simple .NET logging with fully-structured events",
"authors": [ "Serilog Contributors" ],
"tags": [ "serilog", "file", "io" ],
"projectUrl": "http://serilog.net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"iconUrl": "http://serilog.net/images/serilog-sink-nuget.png",
"dependencies": {
"Serilog": { "target": "project" }
},
"compilationOptions": {
"keyFile": "../../assets/Serilog.snk"
},
"frameworks": {
"net45": {
},
"dotnet5.4": {
"dependencies": {
"System.IO": "4.0.11-beta-23516",
"System.IO.FileSystem.Primitives": "4.0.1-beta-23516",
"runtime.osx.10.10.System.IO.FileSystem": "4.0.1-beta-23516",
"runtime.linux.System.IO.FileSystem": "4.0.1-beta-23516",
"runtime.win7.System.IO.FileSystem": "4.0.1-beta-23516"
}
}
}
}
11 changes: 11 additions & 0 deletions src/Serilog.Sinks.RollingFile/Properties/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyVersion("2.0.0.0")]

[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=" +
"0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" +
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" +
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" +
"94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" +
"b19485ec")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting.Display;

namespace Serilog.Sinks.RollingFile
{
public static class RollingFileConfigurationExtensions
{
const int DefaultRetainedFileCountLimit = 31; // A long month of logs

/// <summary>
/// Write log events to a series of files. Each file will be named according to
/// the date of the first log entry written to it. Only simple date-based rolling is
/// currently supported.
/// </summary>
/// <param name="sinkConfiguration">Logger sink configuration.</param>
/// <param name="pathFormat">String describing the location of the log files,
/// with {Date} in the place of the file date. E.g. "Logs\myapp-{Date}.log" will result in log
/// files such as "Logs\myapp-2013-10-20.log", "Logs\myapp-2013-10-21.log" and so on.</param>
/// <param name="restrictedToMinimumLevel">The minimum level for
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
/// to be changed at runtime.</param>
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <param name="fileSizeLimitBytes">The maximum size, in bytes, to which any single log file will be allowed to grow.
/// For unrestricted growth, pass null. The default is 1 GB.</param>
/// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
/// including the current log file. For unlimited retention, pass null. The default is 31.</param>
/// <returns>Configuration object allowing method chaining.</returns>
/// <remarks>The file will be written using the UTF-8 character set.</remarks>
public static LoggerConfiguration RollingFile(
this LoggerSinkConfiguration sinkConfiguration,
string pathFormat,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = LoggerConfigurationFullNetFxExtensions.DefaultOutputTemplate,
IFormatProvider formatProvider = null,
long? fileSizeLimitBytes = LoggerConfigurationFullNetFxExtensions.DefaultFileSizeLimitBytes,
int? retainedFileCountLimit = DefaultRetainedFileCountLimit,
LoggingLevelSwitch levelSwitch = null)
{
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
var sink = new RollingFileSink(pathFormat, formatter, fileSizeLimitBytes, retainedFileCountLimit);
return sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch);
}
}
}
20 changes: 20 additions & 0 deletions src/Serilog.Sinks.RollingFile/Serilog.Sinks.RollingFile.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>a3e6e5b4-995f-4c3d-9673-a4b6000f4e21</ProjectGuid>
<RootNamespace>Serilog.Sinks.RollingFile</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if FILE_IO

using System;

namespace Serilog.Sinks.RollingFile
Expand All @@ -37,5 +35,4 @@ public static void SetTestDateTimeNow(DateTime now)
_dateTimeNow = () => _testDateTimeNow;
}
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if FILE_IO

using System;
using System.IO;
Expand Down Expand Up @@ -226,5 +225,4 @@ void CloseFile()
_nextCheckpoint = null;
}
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#if FILE_IO


using System;

namespace Serilog.Sinks.RollingFile
Expand All @@ -33,5 +31,4 @@ public RollingLogFile(string filename, DateTime date, int sequenceNumber)

public int SequenceNumber { get; }
}
}
#endif
}
Loading

0 comments on commit 0d49b19

Please sign in to comment.