From 0d49b19f0d7a01e7dc63735fa2cba3fd6cdd4bfd Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Wed, 20 Jan 2016 13:05:30 +1000 Subject: [PATCH] Moved IO Sinks to new projects. Dependencies required a combined commit --- Serilog.sln | 14 +++ .../IOFileConfigurationExtensions.cs | 74 +++++++++++ .../Properties/InternalsVisibleTo.cs | 11 ++ .../Serilog.Sinks.IOFile.xproj | 18 +++ .../IOFile/CharacterCountLimitedTextWriter.cs | 7 +- .../Sinks/IOFile/FileSink.cs | 9 +- .../Sinks/IOFile/NullSink.cs | 7 +- src/Serilog.Sinks.IOFile/project.json | 28 +++++ .../Properties/InternalsVisibleTo.cs | 11 ++ .../RollingFileConfigurationExtensions.cs | 52 ++++++++ .../Serilog.Sinks.RollingFile.xproj | 20 +++ .../Sinks/RollingFile/Clock.cs | 5 +- .../Sinks/RollingFile/RollingFileSink.cs | 4 +- .../Sinks/RollingFile/RollingLogFile.cs | 7 +- .../Sinks/RollingFile/TemplatedPathRoller.cs | 7 +- src/Serilog.Sinks.RollingFile/project.json | 29 +++++ .../LoggerConfigurationFullNetFxExtensions.cs | 118 +----------------- .../Settings/KeyValuePairSettingsTests.cs | 24 +--- test/Serilog.Tests/project.json | 4 +- 19 files changed, 277 insertions(+), 172 deletions(-) create mode 100644 src/Serilog.Sinks.IOFile/IOFileConfigurationExtensions.cs create mode 100644 src/Serilog.Sinks.IOFile/Properties/InternalsVisibleTo.cs create mode 100644 src/Serilog.Sinks.IOFile/Serilog.Sinks.IOFile.xproj rename src/{Serilog => Serilog.Sinks.IOFile}/Sinks/IOFile/CharacterCountLimitedTextWriter.cs (97%) rename src/{Serilog => Serilog.Sinks.IOFile}/Sinks/IOFile/FileSink.cs (97%) rename src/{Serilog => Serilog.Sinks.IOFile}/Sinks/IOFile/NullSink.cs (93%) create mode 100644 src/Serilog.Sinks.IOFile/project.json create mode 100644 src/Serilog.Sinks.RollingFile/Properties/InternalsVisibleTo.cs create mode 100644 src/Serilog.Sinks.RollingFile/RollingFileConfigurationExtensions.cs create mode 100644 src/Serilog.Sinks.RollingFile/Serilog.Sinks.RollingFile.xproj rename src/{Serilog => Serilog.Sinks.RollingFile}/Sinks/RollingFile/Clock.cs (98%) rename src/{Serilog => Serilog.Sinks.RollingFile}/Sinks/RollingFile/RollingFileSink.cs (99%) rename src/{Serilog => Serilog.Sinks.RollingFile}/Sinks/RollingFile/RollingLogFile.cs (97%) rename src/{Serilog => Serilog.Sinks.RollingFile}/Sinks/RollingFile/TemplatedPathRoller.cs (99%) create mode 100644 src/Serilog.Sinks.RollingFile/project.json diff --git a/Serilog.sln b/Serilog.sln index 233f2154e..95743ebb0 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -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 @@ -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 @@ -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 diff --git a/src/Serilog.Sinks.IOFile/IOFileConfigurationExtensions.cs b/src/Serilog.Sinks.IOFile/IOFileConfigurationExtensions.cs new file mode 100644 index 000000000..231d9b62f --- /dev/null +++ b/src/Serilog.Sinks.IOFile/IOFileConfigurationExtensions.cs @@ -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 + { + /// + /// Write log events to the specified file. + /// + /// Logger sink configuration. + /// Path to the file. + /// The minimum level for + /// events passed through the sink. Ignored when is specified. + /// A switch allowing the pass-through minimum level + /// to be changed at runtime. + /// Supplies culture-specific formatting information, or null. + /// A message template describing the format used to write to the sink. + /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}". + /// 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. + /// Configuration object allowing method chaining. + /// The file will be written using the UTF-8 character set. + 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); + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.IOFile/Properties/InternalsVisibleTo.cs b/src/Serilog.Sinks.IOFile/Properties/InternalsVisibleTo.cs new file mode 100644 index 000000000..dd34d0bdb --- /dev/null +++ b/src/Serilog.Sinks.IOFile/Properties/InternalsVisibleTo.cs @@ -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")] diff --git a/src/Serilog.Sinks.IOFile/Serilog.Sinks.IOFile.xproj b/src/Serilog.Sinks.IOFile/Serilog.Sinks.IOFile.xproj new file mode 100644 index 000000000..250fa02af --- /dev/null +++ b/src/Serilog.Sinks.IOFile/Serilog.Sinks.IOFile.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 57e0ed0e-0f45-48ab-a73d-6a92b7c32095 + Serilog + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Serilog/Sinks/IOFile/CharacterCountLimitedTextWriter.cs b/src/Serilog.Sinks.IOFile/Sinks/IOFile/CharacterCountLimitedTextWriter.cs similarity index 97% rename from src/Serilog/Sinks/IOFile/CharacterCountLimitedTextWriter.cs rename to src/Serilog.Sinks.IOFile/Sinks/IOFile/CharacterCountLimitedTextWriter.cs index 943209a0f..24687a487 100644 --- a/src/Serilog/Sinks/IOFile/CharacterCountLimitedTextWriter.cs +++ b/src/Serilog.Sinks.IOFile/Sinks/IOFile/CharacterCountLimitedTextWriter.cs @@ -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. @@ -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; @@ -73,5 +71,4 @@ public override void Write(char[] buffer, int index, int count) public override void Flush() => _outputWriter.Flush(); } -} -#endif +} \ No newline at end of file diff --git a/src/Serilog/Sinks/IOFile/FileSink.cs b/src/Serilog.Sinks.IOFile/Sinks/IOFile/FileSink.cs similarity index 97% rename from src/Serilog/Sinks/IOFile/FileSink.cs rename to src/Serilog.Sinks.IOFile/Sinks/IOFile/FileSink.cs index e43ba6867..4f0ad0d2b 100644 --- a/src/Serilog/Sinks/IOFile/FileSink.cs +++ b/src/Serilog.Sinks.IOFile/Sinks/IOFile/FileSink.cs @@ -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. @@ -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; @@ -103,5 +101,4 @@ public void Emit(LogEvent logEvent) /// public void Dispose() => _output.Dispose(); } -} -#endif +} \ No newline at end of file diff --git a/src/Serilog/Sinks/IOFile/NullSink.cs b/src/Serilog.Sinks.IOFile/Sinks/IOFile/NullSink.cs similarity index 93% rename from src/Serilog/Sinks/IOFile/NullSink.cs rename to src/Serilog.Sinks.IOFile/Sinks/IOFile/NullSink.cs index 49d4f16b8..57789af1b 100644 --- a/src/Serilog/Sinks/IOFile/NullSink.cs +++ b/src/Serilog.Sinks.IOFile/Sinks/IOFile/NullSink.cs @@ -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. @@ -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; @@ -29,5 +27,4 @@ public void Emit(LogEvent logEvent) { } } -} -#endif +} \ No newline at end of file diff --git a/src/Serilog.Sinks.IOFile/project.json b/src/Serilog.Sinks.IOFile/project.json new file mode 100644 index 000000000..8762bd2a1 --- /dev/null +++ b/src/Serilog.Sinks.IOFile/project.json @@ -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" + } + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.RollingFile/Properties/InternalsVisibleTo.cs b/src/Serilog.Sinks.RollingFile/Properties/InternalsVisibleTo.cs new file mode 100644 index 000000000..dd34d0bdb --- /dev/null +++ b/src/Serilog.Sinks.RollingFile/Properties/InternalsVisibleTo.cs @@ -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")] diff --git a/src/Serilog.Sinks.RollingFile/RollingFileConfigurationExtensions.cs b/src/Serilog.Sinks.RollingFile/RollingFileConfigurationExtensions.cs new file mode 100644 index 000000000..e2b64d0bf --- /dev/null +++ b/src/Serilog.Sinks.RollingFile/RollingFileConfigurationExtensions.cs @@ -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 + + /// + /// 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. + /// + /// Logger sink configuration. + /// 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. + /// The minimum level for + /// events passed through the sink. Ignored when is specified. + /// A switch allowing the pass-through minimum level + /// to be changed at runtime. + /// A message template describing the format used to write to the sink. + /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}". + /// Supplies culture-specific formatting information, or null. + /// 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. + /// The maximum number of log files that will be retained, + /// including the current log file. For unlimited retention, pass null. The default is 31. + /// Configuration object allowing method chaining. + /// The file will be written using the UTF-8 character set. + 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); + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.RollingFile/Serilog.Sinks.RollingFile.xproj b/src/Serilog.Sinks.RollingFile/Serilog.Sinks.RollingFile.xproj new file mode 100644 index 000000000..530696272 --- /dev/null +++ b/src/Serilog.Sinks.RollingFile/Serilog.Sinks.RollingFile.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + a3e6e5b4-995f-4c3d-9673-a4b6000f4e21 + Serilog.Sinks.RollingFile + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/src/Serilog/Sinks/RollingFile/Clock.cs b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/Clock.cs similarity index 98% rename from src/Serilog/Sinks/RollingFile/Clock.cs rename to src/Serilog.Sinks.RollingFile/Sinks/RollingFile/Clock.cs index 7c210af62..d45490ad8 100644 --- a/src/Serilog/Sinks/RollingFile/Clock.cs +++ b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/Clock.cs @@ -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 @@ -37,5 +35,4 @@ public static void SetTestDateTimeNow(DateTime now) _dateTimeNow = () => _testDateTimeNow; } } -} -#endif +} \ No newline at end of file diff --git a/src/Serilog/Sinks/RollingFile/RollingFileSink.cs b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingFileSink.cs similarity index 99% rename from src/Serilog/Sinks/RollingFile/RollingFileSink.cs rename to src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingFileSink.cs index 7eb061dd5..f775b55cf 100644 --- a/src/Serilog/Sinks/RollingFile/RollingFileSink.cs +++ b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingFileSink.cs @@ -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; @@ -226,5 +225,4 @@ void CloseFile() _nextCheckpoint = null; } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Serilog/Sinks/RollingFile/RollingLogFile.cs b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingLogFile.cs similarity index 97% rename from src/Serilog/Sinks/RollingFile/RollingLogFile.cs rename to src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingLogFile.cs index a1964a6b8..d285cace0 100644 --- a/src/Serilog/Sinks/RollingFile/RollingLogFile.cs +++ b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingLogFile.cs @@ -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 @@ -33,5 +31,4 @@ public RollingLogFile(string filename, DateTime date, int sequenceNumber) public int SequenceNumber { get; } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Serilog/Sinks/RollingFile/TemplatedPathRoller.cs b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/TemplatedPathRoller.cs similarity index 99% rename from src/Serilog/Sinks/RollingFile/TemplatedPathRoller.cs rename to src/Serilog.Sinks.RollingFile/Sinks/RollingFile/TemplatedPathRoller.cs index cf7f3ec84..e0950da4e 100644 --- a/src/Serilog/Sinks/RollingFile/TemplatedPathRoller.cs +++ b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/TemplatedPathRoller.cs @@ -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; using System.Collections.Generic; using System.Globalization; @@ -125,5 +123,4 @@ public IEnumerable SelectMatches(IEnumerable filenames) } } } -} -#endif +} \ No newline at end of file diff --git a/src/Serilog.Sinks.RollingFile/project.json b/src/Serilog.Sinks.RollingFile/project.json new file mode 100644 index 000000000..7ca38721e --- /dev/null +++ b/src/Serilog.Sinks.RollingFile/project.json @@ -0,0 +1,29 @@ +{ + "version": "2.0.0-beta-*", + "description": "The rolling file sink for Serilog - Simple .NET logging with fully-structured events", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "file", "io", "rolling" ], + "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" }, + "Serilog.Sinks.IOFile": { "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" + } + } + } +} \ No newline at end of file diff --git a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs index 13426406e..acb5a403d 100644 --- a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs +++ b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs @@ -27,10 +27,6 @@ using System.Diagnostics; #endif -#if FILE_IO -using Serilog.Sinks.IOFile; -using Serilog.Sinks.RollingFile; -#endif #if APPSETTINGS using Serilog.Settings.AppSettings; @@ -44,13 +40,11 @@ namespace Serilog /// public static class LoggerConfigurationFullNetFxExtensions { - //TODO: Need to confirm this is the best location for this default. Used in File, Trace, RollingFike + //TODO: Need to confirm this is the best location for this default. Used in File, Trace, RollingFile. Do we move this to each sink? public const string DefaultOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"; + public const long DefaultFileSizeLimitBytes = 1L * 1024 * 1024 * 1024; const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"; - const long DefaultFileSizeLimitBytes = 1L * 1024 * 1024 * 1024; - const int DefaultRetainedFileCountLimit = 31; // A long month of logs - - + /// /// Writes log events to , using color to differentiate /// between levels. @@ -76,112 +70,6 @@ public static LoggerConfiguration ColoredConsole( return sinkConfiguration.Sink(new ColoredConsoleSink(outputTemplate, formatProvider), restrictedToMinimumLevel, levelSwitch); } -#if FILE_IO - /// - /// Write log events in a simple text dump format to the specified file. - /// - /// Logger sink configuration. - /// Path to the dump file. - /// The minimum level for - /// events passed through the sink. - /// Configuration object allowing method chaining. - [Obsolete("Please use WriteTo.Sink(new FileSink(path, new RawFormatter(), null)) instead", true), EditorBrowsable(EditorBrowsableState.Never)] - public static LoggerConfiguration DumpFile( - this LoggerSinkConfiguration sinkConfiguration, - string path, - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum) - { - if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); - if (path == null) throw new ArgumentNullException(nameof(path)); - return sinkConfiguration.Sink(new FileSink(path, new RawFormatter(), null), restrictedToMinimumLevel); - } - - /// - /// Write log events to the specified file. - /// - /// Logger sink configuration. - /// Path to the file. - /// The minimum level for - /// events passed through the sink. Ignored when is specified. - /// A switch allowing the pass-through minimum level - /// to be changed at runtime. - /// Supplies culture-specific formatting information, or null. - /// A message template describing the format used to write to the sink. - /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}". - /// 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. - /// Configuration object allowing method chaining. - /// The file will be written using the UTF-8 character set. - public static LoggerConfiguration File( - this LoggerSinkConfiguration sinkConfiguration, - string path, - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, - string outputTemplate = DefaultOutputTemplate, - IFormatProvider formatProvider = null, - long? fileSizeLimitBytes = 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); - } - - /// - /// 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. - /// - /// Logger sink configuration. - /// 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. - /// The minimum level for - /// events passed through the sink. Ignored when is specified. - /// A switch allowing the pass-through minimum level - /// to be changed at runtime. - /// A message template describing the format used to write to the sink. - /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}". - /// Supplies culture-specific formatting information, or null. - /// 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. - /// The maximum number of log files that will be retained, - /// including the current log file. For unlimited retention, pass null. The default is 31. - /// Configuration object allowing method chaining. - /// The file will be written using the UTF-8 character set. - public static LoggerConfiguration RollingFile( - this LoggerSinkConfiguration sinkConfiguration, - string pathFormat, - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, - string outputTemplate = DefaultOutputTemplate, - IFormatProvider formatProvider = null, - long? fileSizeLimitBytes = 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); - } -#endif #if LOGCONTEXT /// diff --git a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs index 9a6a5d9a4..77c4705c8 100644 --- a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs +++ b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs @@ -55,29 +55,7 @@ public void FindsConfigurationAssemblies() // The core Serilog assembly is always considered Assert.Equal(1, configurationAssemblies.Count); - } - - [Fact] - public void FindsConfigurationMethodsWithinAnAssembly() - { - var configurationMethods = KeyValuePairSettings - .FindSinkConfigurationMethods(new[] { typeof(RollingFileSink) -#if DNXCORE50 - .GetTypeInfo() -#endif - .Assembly - }) - .Select(m => m.Name) - .Distinct() - .ToList(); - - Assert.Equal(4, configurationMethods.Count); - - Assert.True(configurationMethods.Contains("ColoredConsole")); - Assert.True(configurationMethods.Contains("DumpFile")); - Assert.True(configurationMethods.Contains("File")); - Assert.True(configurationMethods.Contains("RollingFile")); - } + } [Fact] public void FindsEventEnrichersWithinAnAssembly() diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index 06c5beb3f..945fb5af5 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -12,7 +12,9 @@ "xunit.runner.visualstudio": "2.1.0", "xunit.runner.dnx": "2.1.0-rc1-build204", "Serilog.Sinks.Console": { "target": "project" }, - "Serilog.Sinks.DiagnosticTrace": { "target": "project" } + "Serilog.Sinks.DiagnosticTrace": { "target": "project" }, + "Serilog.Sinks.IOFile": { "target": "project" }, + "Serilog.Sinks.RollingFile": {"target": "project"} }, "frameworks": { "dnx451": {