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.
Moved IO Sinks to new projects. Dependencies required a combined commit
- Loading branch information
Showing
19 changed files
with
277 additions
and
172 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
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); | ||
} | ||
} | ||
} |
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,11 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyVersion("2.0.0.0")] | ||
|
||
[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=" + | ||
"0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + | ||
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + | ||
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + | ||
"94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + | ||
"b19485ec")] |
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,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> |
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
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
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
11
src/Serilog.Sinks.RollingFile/Properties/InternalsVisibleTo.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,11 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyVersion("2.0.0.0")] | ||
|
||
[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=" + | ||
"0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + | ||
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + | ||
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + | ||
"94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + | ||
"b19485ec")] |
52 changes: 52 additions & 0 deletions
52
src/Serilog.Sinks.RollingFile/RollingFileConfigurationExtensions.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,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
20
src/Serilog.Sinks.RollingFile/Serilog.Sinks.RollingFile.xproj
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,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> |
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
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.