From 55bdd45f4686f41d92441f9dbe45d47f4ffde0a3 Mon Sep 17 00:00:00 2001 From: Vasily Vasilyev Date: Sat, 9 Apr 2022 17:29:41 +0200 Subject: [PATCH] #14 refactoring: add project templates and logging library --- .../ClipChopper.DesktopApp.csproj | 51 +- .../ClipChopper.DesktopApp/MainWindow.xaml.cs | 2 +- ClipChopper/ClipChopper.sln | 31 +- ClipChopper/Directory.Build.props | 26 + .../ClipChopper.Common.csproj | 39 + .../ClipChopper.Core/ClipChopper.Core.csproj | 43 + .../ClipChopper.Logging.csproj | 60 + .../Libraries/ClipChopper.Logging/ILogger.cs | 16 + .../ClipChopper.Logging/LoggerFactory.cs | 46 + .../Libraries/ClipChopper.Logging/NLog.config | 52 + .../Libraries/ClipChopper.Logging/NLog.xsd | 3168 +++++++++++++++++ .../IndentExceptionLayoutRenderer.cs | 143 + ...laceNewLinesFormatWrapperLayoutRenderer.cs | 52 + .../NLog/NLogLoggerAdapter.cs | 115 + ClipChopper/NuGet.Config | 6 + ClipChopper/global.json | 7 - 16 files changed, 3828 insertions(+), 29 deletions(-) create mode 100644 ClipChopper/Directory.Build.props create mode 100644 ClipChopper/Libraries/ClipChopper.Common/ClipChopper.Common.csproj create mode 100644 ClipChopper/Libraries/ClipChopper.Core/ClipChopper.Core.csproj create mode 100644 ClipChopper/Libraries/ClipChopper.Logging/ClipChopper.Logging.csproj create mode 100644 ClipChopper/Libraries/ClipChopper.Logging/ILogger.cs create mode 100644 ClipChopper/Libraries/ClipChopper.Logging/LoggerFactory.cs create mode 100644 ClipChopper/Libraries/ClipChopper.Logging/NLog.config create mode 100644 ClipChopper/Libraries/ClipChopper.Logging/NLog.xsd create mode 100644 ClipChopper/Libraries/ClipChopper.Logging/NLog/Extensions/IndentExceptionLayoutRenderer.cs create mode 100644 ClipChopper/Libraries/ClipChopper.Logging/NLog/Extensions/ReplaceNewLinesFormatWrapperLayoutRenderer.cs create mode 100644 ClipChopper/Libraries/ClipChopper.Logging/NLog/NLogLoggerAdapter.cs create mode 100644 ClipChopper/NuGet.Config delete mode 100644 ClipChopper/global.json diff --git a/ClipChopper/Applications/ClipChopper.DesktopApp/ClipChopper.DesktopApp.csproj b/ClipChopper/Applications/ClipChopper.DesktopApp/ClipChopper.DesktopApp.csproj index 84d3c26..613eaef 100644 --- a/ClipChopper/Applications/ClipChopper.DesktopApp/ClipChopper.DesktopApp.csproj +++ b/ClipChopper/Applications/ClipChopper.DesktopApp/ClipChopper.DesktopApp.csproj @@ -1,30 +1,36 @@ - + - Valery Kirichenko - ClipChopper - ClipChopper - ClipChopper - Valery Kirichenko - - x64 - Debug;Release + $(AppPlatforms) + $(AppConfigurations) WinExe - net6.0-windows - 8.0 + $(WindowsAppTargetFramework) + $(CSharpLangVersion) true enable - CS8600,CS8602,CS8603,CS8618,CS8625 - ClipChopper + true + true + v + ClipChopper.DesktopApp + false + false icon.ico MinimumRecommendedRules.ruleset + true true win-x64 + - 1.2.1 - 1.2.1 + + Valery Kirichenko; Vasily Vasilyev + ClipChopper + ClipChopper + en-US + https://github.com/valery-kirichenko/clip-chopper + true + git @@ -67,9 +73,16 @@ - - - + + + + + + + + + + - \ No newline at end of file + diff --git a/ClipChopper/Applications/ClipChopper.DesktopApp/MainWindow.xaml.cs b/ClipChopper/Applications/ClipChopper.DesktopApp/MainWindow.xaml.cs index 329b636..55af31d 100644 --- a/ClipChopper/Applications/ClipChopper.DesktopApp/MainWindow.xaml.cs +++ b/ClipChopper/Applications/ClipChopper.DesktopApp/MainWindow.xaml.cs @@ -29,7 +29,7 @@ public sealed partial class MainWindow private string? _loadedMedia; private FragmentSelection? _fragment; private int _selectedAudioStream; - public ObservableCollection AudioTracks { get; } = new ObservableCollection(new List + public ObservableCollection AudioTracks { get; } = new(new List { new AudioTrack { diff --git a/ClipChopper/ClipChopper.sln b/ClipChopper/ClipChopper.sln index c65cba2..0631847 100644 --- a/ClipChopper/ClipChopper.sln +++ b/ClipChopper/ClipChopper.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29709.97 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32328.378 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Applications", "Applications", "{30A9B94B-57FE-4C5D-B493-2E8F2D578AF8}" EndProject @@ -11,6 +11,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C2130176 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClipChopper.DesktopApp", "Applications\ClipChopper.DesktopApp\ClipChopper.DesktopApp.csproj", "{72CA55A6-B3C2-4779-818D-CC49758C2A15}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{30D71C54-EDCC-4DB5-8609-87B1FCD6A517}" + ProjectSection(SolutionItems) = preProject + Directory.Build.props = Directory.Build.props + NuGet.Config = NuGet.Config + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClipChopper.Core", "Libraries\ClipChopper.Core\ClipChopper.Core.csproj", "{89AE0DD0-1B71-4DF1-856C-EC3A12BDDFEE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClipChopper.Logging", "Libraries\ClipChopper.Logging\ClipChopper.Logging.csproj", "{15230E04-1457-4A66-A1CC-E74F01DA9EB0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClipChopper.Common", "Libraries\ClipChopper.Common\ClipChopper.Common.csproj", "{12A8C3E5-96AE-4374-A721-7276AAF31D4D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -22,12 +34,27 @@ Global {72CA55A6-B3C2-4779-818D-CC49758C2A15}.Release|x64.ActiveCfg = Release|x64 {72CA55A6-B3C2-4779-818D-CC49758C2A15}.Release|x64.Build.0 = Release|x64 {72CA55A6-B3C2-4779-818D-CC49758C2A15}.Release|x64.Deploy.0 = Release|x64 + {89AE0DD0-1B71-4DF1-856C-EC3A12BDDFEE}.Debug|x64.ActiveCfg = Debug|x64 + {89AE0DD0-1B71-4DF1-856C-EC3A12BDDFEE}.Debug|x64.Build.0 = Debug|x64 + {89AE0DD0-1B71-4DF1-856C-EC3A12BDDFEE}.Release|x64.ActiveCfg = Release|x64 + {89AE0DD0-1B71-4DF1-856C-EC3A12BDDFEE}.Release|x64.Build.0 = Release|x64 + {15230E04-1457-4A66-A1CC-E74F01DA9EB0}.Debug|x64.ActiveCfg = Debug|x64 + {15230E04-1457-4A66-A1CC-E74F01DA9EB0}.Debug|x64.Build.0 = Debug|x64 + {15230E04-1457-4A66-A1CC-E74F01DA9EB0}.Release|x64.ActiveCfg = Release|x64 + {15230E04-1457-4A66-A1CC-E74F01DA9EB0}.Release|x64.Build.0 = Release|x64 + {12A8C3E5-96AE-4374-A721-7276AAF31D4D}.Debug|x64.ActiveCfg = Debug|x64 + {12A8C3E5-96AE-4374-A721-7276AAF31D4D}.Debug|x64.Build.0 = Debug|x64 + {12A8C3E5-96AE-4374-A721-7276AAF31D4D}.Release|x64.ActiveCfg = Release|x64 + {12A8C3E5-96AE-4374-A721-7276AAF31D4D}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {72CA55A6-B3C2-4779-818D-CC49758C2A15} = {30A9B94B-57FE-4C5D-B493-2E8F2D578AF8} + {89AE0DD0-1B71-4DF1-856C-EC3A12BDDFEE} = {A4D3BDEB-BB70-46BC-BB8C-B58D71922315} + {15230E04-1457-4A66-A1CC-E74F01DA9EB0} = {A4D3BDEB-BB70-46BC-BB8C-B58D71922315} + {12A8C3E5-96AE-4374-A721-7276AAF31D4D} = {A4D3BDEB-BB70-46BC-BB8C-B58D71922315} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D5421CE1-B974-4F27-83D9-6EACD36B29A4} diff --git a/ClipChopper/Directory.Build.props b/ClipChopper/Directory.Build.props new file mode 100644 index 0000000..752edc6 --- /dev/null +++ b/ClipChopper/Directory.Build.props @@ -0,0 +1,26 @@ + + + + + x64 + Debug;Release + net6.0 + net6.0-windows + net6.0 + net6.0 + 10.0 + + + + + 2.2.0 + 4.4.350 + 0.11.0 + 3.1.0 + 4.7.15 + 4.7.15 + 4.7.15 + 5.0.1 + + + diff --git a/ClipChopper/Libraries/ClipChopper.Common/ClipChopper.Common.csproj b/ClipChopper/Libraries/ClipChopper.Common/ClipChopper.Common.csproj new file mode 100644 index 0000000..3588e6a --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Common/ClipChopper.Common.csproj @@ -0,0 +1,39 @@ + + + + $(AppPlatforms) + $(AppConfigurations) + Library + $(LibraryTargetFramework) + $(CSharpLangVersion) + enable + true + true + v + ClipChopper.Common + false + false + MinimumRecommendedRules.ruleset + + true + + true + win-x64 + + + + Valery Kirichenko; Vasily Vasilyev + ClipChopper + ClipChopper + en-US + https://github.com/valery-kirichenko/clip-chopper + true + git + + + + + + + + diff --git a/ClipChopper/Libraries/ClipChopper.Core/ClipChopper.Core.csproj b/ClipChopper/Libraries/ClipChopper.Core/ClipChopper.Core.csproj new file mode 100644 index 0000000..b5266a9 --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Core/ClipChopper.Core.csproj @@ -0,0 +1,43 @@ + + + + $(AppPlatforms) + $(AppConfigurations) + Library + $(LibraryTargetFramework) + $(CSharpLangVersion) + enable + true + true + v + ClipChopper.Core + false + false + MinimumRecommendedRules.ruleset + + true + + true + win-x64 + + + + Valery Kirichenko; Vasily Vasilyev + ClipChopper + ClipChopper + en-US + https://github.com/valery-kirichenko/clip-chopper + true + git + + + + + + + + + + + + diff --git a/ClipChopper/Libraries/ClipChopper.Logging/ClipChopper.Logging.csproj b/ClipChopper/Libraries/ClipChopper.Logging/ClipChopper.Logging.csproj new file mode 100644 index 0000000..f57da73 --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Logging/ClipChopper.Logging.csproj @@ -0,0 +1,60 @@ + + + + $(AppPlatforms) + $(AppConfigurations) + Library + $(LibraryTargetFramework) + $(CSharpLangVersion) + enable + true + true + v + ClipChopper.Logging + false + false + MinimumRecommendedRules.ruleset + + true + + true + win-x64 + + + + Valery Kirichenko; Vasily Vasilyev + ClipChopper + ClipChopper + en-US + https://github.com/valery-kirichenko/clip-chopper + true + git + + + + + + + + + + + all + + + + + + + PreserveNewest + false + PreserveNewest + + + PreserveNewest + false + PreserveNewest + + + + diff --git a/ClipChopper/Libraries/ClipChopper.Logging/ILogger.cs b/ClipChopper/Libraries/ClipChopper.Logging/ILogger.cs new file mode 100644 index 0000000..dfc99ed --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Logging/ILogger.cs @@ -0,0 +1,16 @@ +using System; + +namespace ClipChopper.Logging +{ + public interface ILogger + { + void PrintHeader(string message); + void PrintFooter(string message); + void Debug(string message); + void Info(string message); + void Warn(string message); + void Warn(Exception ex, string message); + void Error(string message); + void Error(Exception ex, string message); + } +} diff --git a/ClipChopper/Libraries/ClipChopper.Logging/LoggerFactory.cs b/ClipChopper/Libraries/ClipChopper.Logging/LoggerFactory.cs new file mode 100644 index 0000000..4989f87 --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Logging/LoggerFactory.cs @@ -0,0 +1,46 @@ +using System; +using Acolyte.Assertions; + +namespace ClipChopper.Logging +{ + public static class LoggerFactory + { + /// + /// Creates logger instance for passed type. + /// + /// Type for which instance is created. + /// Created logger instance. + /// + /// Cannot get full name of type . + /// + public static ILogger CreateLoggerFor() + { + Type type = typeof(T); + string fullName = type.FullName ?? throw new ArgumentException( + $"Could not get full name of class {type}." + ); + return new NLogLoggerAdapter(fullName); + } + + /// + /// Creates logger instance for passed class type. + /// + /// Class name. Try to pass it with typeof operator. + /// Created logger instance. + /// + /// is null. + /// + /// + /// Cannot get full name of passed type . + /// + public static ILogger CreateLoggerFor(Type type) + { + type.ThrowIfNull(nameof(type)); + + string fullName = type.FullName ?? throw new ArgumentException( + $"Could not get full name of class {nameof(type)}" + ); + return new NLogLoggerAdapter(fullName); + } + } +} diff --git a/ClipChopper/Libraries/ClipChopper.Logging/NLog.config b/ClipChopper/Libraries/ClipChopper.Logging/NLog.config new file mode 100644 index 0000000..5ebc999 --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Logging/NLog.config @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClipChopper/Libraries/ClipChopper.Logging/NLog.xsd b/ClipChopper/Libraries/ClipChopper.Logging/NLog.xsd new file mode 100644 index 0000000..075bb91 --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Logging/NLog.xsd @@ -0,0 +1,3168 @@ + + + + + + + + + + + + + + + Watch config file for changes and reload automatically. + + + + + Print internal NLog messages to the console. Default value is: false + + + + + Print internal NLog messages to the console error output. Default value is: false + + + + + Write internal NLog messages to the specified file. + + + + + Log level threshold for internal log messages. Default value is: Info. + + + + + Global log level threshold for application log messages. Messages below this level won't be logged.. + + + + + Throw an exception when there is an internal error. Default value is: false. + + + + + Throw an exception when there is a configuration error. If not set, determined by throwExceptions. + + + + + Gets or sets a value indicating whether Variables should be kept on configuration reload. Default value is: false. + + + + + Write internal NLog messages to the System.Diagnostics.Trace. Default value is: false. + + + + + Write timestamps for internal NLog messages. Default value is: true. + + + + + Use InvariantCulture as default culture instead of CurrentCulture. Default value is: false. + + + + + Perform mesage template parsing and formatting of LogEvent messages (true = Always, false = Never, empty = Auto Detect). Default value is: empty. + + + + + + + + + + + + + + Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes). + + + + + + + + + + + + + + + + + Prefix for targets/layout renderers/filters/conditions loaded from this assembly. + + + + + Load NLog extensions from the specified file (*.dll) + + + + + Load NLog extensions from the specified assembly. Assembly name should be fully qualified. + + + + + + + + + + Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name* + + + + + Comma separated list of levels that this rule matches. + + + + + Minimum level that this rule matches. + + + + + Maximum level that this rule matches. + + + + + Level that this rule matches. + + + + + Comma separated list of target names. + + + + + Ignore further rules if this one matches. + + + + + Enable or disable logging rule. Disabled rules are ignored. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the file to be included. You could use * wildcard. The name is relative to the name of the current config file. + + + + + Ignore any errors in the include file. + + + + + + + Variable name. + + + + + Variable value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events that should be processed in a batch by the lazy writer thread. + + + + + Limit of full s to write before yielding into Performance is better when writing many small batches, than writing a single large batch + + + + + Action to be taken when the lazy writer thread request queue count exceeds the set limit. + + + + + Limit on the number of requests in the lazy writer thread request queue. + + + + + Time in milliseconds to sleep between batches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + Delay the flush until the LogEvent has been confirmed as written + + + + + Condition expression. Log events who meet this condition will cause a flush on the wrapped target. + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events to be buffered. + + + + + Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes. + + + + + Action to take if the buffer overflows. + + + + + Indicates whether to use sliding timeout. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Maximum queue size. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + NDLC item separator. + + + + + NDC item separator. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + Option to include all properties from the log events + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Renderer for log4j:event logger-xml-attribute (Default ${logger}) + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Viewer parameter name. + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to auto-check if the console is available. - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). + + + + + Indicates whether to use default row highlighting rules. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Condition that must be met in order to set the specified foreground and background color. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + Compile the ? This can improve the performance, but at the costs of more memory usage. If false, the Regex Cache is used. + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to auto-check if the console is available - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Indicates whether to send the log messages to the standard error instead of the standard output. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Obsolete - value will be ignored! The logging code always runs outside of transaction. Gets or sets a value indicating whether to use database transactions. Some data providers require this. + + + + + Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. + + + + + Name of the database provider. + + + + + Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. + + + + + Indicates whether to keep the database connection open between the log events. + + + + + Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. + + + + + Name of the connection string (as specified in <connectionStrings> configuration section. + + + + + Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. + + + + + Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. + + + + + Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Text of the SQL command to be run on each log level. + + + + + Type of the SQL command to be run on each log level. + + + + + + + + + + + + + + + + + + + + + + + Type of the command. + + + + + Connection string to run the command against. If not provided, connection string from the target is used. + + + + + Indicates whether to ignore failures. + + + + + Command text. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Database parameter name. + + + + + Database parameter precision. + + + + + Database parameter scale. + + + + + Database parameter size. + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Layout that renders event Category. + + + + + Optional entrytype. When not set, or when not convertable to then determined by + + + + + Layout that renders event ID. + + + + + Name of the Event Log to write to. This can be System, Application or any user-defined name. + + + + + Name of the machine on which Event Log service is running. + + + + + Maximum Event log size in kilobytes. If null, the value won't be set. Default is 512 Kilobytes as specified by Eventlog API + + + + + Message length limit to write to the Event Log. + + + + + Value to be used as the event Source. + + + + + Action to take if the message is larger than the option. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to return to the first target after any successful write. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + File encoding. + + + + + Line ending mode. + + + + + Indicates whether to compress archive files into the zip archive format. + + + + + Way file archives are numbered. + + + + + Name of the file to be used for an archive. + + + + + Is the an absolute or relative path? + + + + + Indicates whether to automatically archive log files every time the specified time passes. + + + + + Size in bytes above which log files will be automatically archived. Warning: combining this with isn't supported. We cannot create multiple archive files, if they should have the same name. Choose: + + + + + Maximum number of archive files that should be kept. + + + + + Indicates whether the footer should be written only when the file is archived. + + + + + Maximum number of log filenames that should be stored as existing. + + + + + Is the an absolute or relative path? + + + + + Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation. + + + + + Value indicationg whether file creation calls should be synchronized by a system global mutex. + + + + + Indicates whether to replace file contents on each write instead of appending log message at the end. + + + + + Indicates whether to write BOM (byte order mark) in created files + + + + + Indicates whether to enable log file(s) to be deleted. + + + + + Name of the file to write to. + + + + + Value specifying the date format to use when archiving files. + + + + + Indicates whether to archive old log file on startup. + + + + + Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong. + + + + + Indicates whether to create directories if they do not exist. + + + + + Indicates whether to delete old log file on startup. + + + + + File attributes (Windows only). + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Indicates whether concurrent writes to the log file by multiple processes on different network hosts. + + + + + Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity. + + + + + Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger). + + + + + Indicates whether to keep log file open instead of opening and closing it on each logging event. + + + + + Whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write + + + + + Indicates whether concurrent writes to the log file by multiple processes on the same host. + + + + + Number of times the write is appended on the file before NLog discards the log message. + + + + + Delay in milliseconds to wait before attempting to write to the file again. + + + + + Log file buffer size in bytes. + + + + + Maximum number of seconds before open files are flushed. If this number is negative or zero the files are not flushed by timer. + + + + + Indicates whether to automatically flush the file buffers after each log message. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Condition expression. Log events who meet this condition will be forwarded to the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Windows domain name to change context to. + + + + + Required impersonation level. + + + + + Type of the logon provider. + + + + + Logon Type. + + + + + User account password. + + + + + Indicates whether to revert to the credentials of the process instead of impersonating another user. + + + + + Username to change context to. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Interval in which messages will be written up to the number of messages. + + + + + Maximum allowed number of messages written per . + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Endpoint address. + + + + + Name of the endpoint configuration in WCF configuration file. + + + + + Indicates whether to use a WCF service contract that is one way (fire and forget) or two way (request-reply) + + + + + Client ID. + + + + + Indicates whether to include per-event properties in the payload sent to the server. + + + + + Indicates whether to use binary message encoding. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + Layout that should be use to calculate the value for the parameter. + + + + + Name of the parameter. + + + + + Type of the parameter. + + + + + Type of the parameter. Obsolete alias for + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether NewLine characters in the body should be replaced with tags. + + + + + Priority used for sending mails. + + + + + Encoding to be used for sending e-mail. + + + + + BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Indicates whether to add new lines between log entries. + + + + + Indicates whether to send message as HTML instead of plain text. + + + + + Sender's email address (e.g. joe@domain.com). + + + + + Mail message body (repeated for each log message send in one mail). + + + + + Mail subject. + + + + + Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Indicates the SMTP client timeout. + + + + + SMTP Server to be used for sending. + + + + + SMTP Authentication mode. + + + + + Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server. + + + + + Port number that SMTP Server is listening on. + + + + + Indicates whether the default Settings from System.Net.MailSettings should be used. + + + + + Folder where applications save mail messages to be processed by the local SMTP server. + + + + + Specifies how outgoing email messages will be handled. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Class name. + + + + + Method name. The method must be public and static. Use the AssemblyQualifiedName , https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx e.g. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Encoding to be used. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Network address. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Indicates whether to keep connection open whenever possible. + + + + + Maximum current connections. 0 = no maximum. + + + + + Maximum queue size. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Maximum queue size. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + NDLC item separator. + + + + + NDC item separator. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + Option to include all properties from the log events + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Renderer for log4j:event logger-xml-attribute (Default ${logger}) + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether to perform layout calculation. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether performance counter should be automatically created. + + + + + Name of the performance counter category. + + + + + Counter help text. + + + + + Name of the performance counter. + + + + + Performance counter type. + + + + + The value by which to increment the counter. + + + + + Performance counter instance name. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Default filter to be applied when no specific rule matches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + Condition to be tested. + + + + + Resulting filter to be applied when the condition matches. + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of times to repeat each log message. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of retries that should be attempted on the wrapped target in case of a failure. + + + + + Time to wait between retries in milliseconds. + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Always use independent of + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Should we include the BOM (Byte-order-mark) for UTF? Influences the property. This will only work for UTF-8. + + + + + Web service method name. Only used with Soap. + + + + + Web service namespace. Only used with Soap. + + + + + Protocol to be used when calling web service. + + + + + Custom proxy address, include port separated by a colon + + + + + Encoding. + + + + + Web service URL. + + + + + Value whether escaping be done according to the old NLog style (Very non-standard) + + + + + Value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs) + + + + + Indicates whether to pre-authenticate the HttpWebRequest (Requires 'Authorization' in parameters) + + + + + Name of the root XML element, if POST of XML document chosen. If so, this property must not be null. (see and ). + + + + + (optional) root namespace of the XML document, if POST of XML document chosen. (see and ). + + + + + Proxy configuration when calling web service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom'). + + + + + Column delimiter. + + + + + Quote Character. + + + + + Quoting mode. + + + + + Indicates whether CVS should include header. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout of the column. + + + + + Name of the column. + + + + + + + + + + + + + + + + + + + List of property names to exclude when is true + + + + + Option to include all properties from the log event (as JSON) + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + + + + Option to render the empty object value {} + + + + + Option to suppress the extra spaces in the output json + + + + + How far should the JSON serializer follow object references before backing off + + + + + + + + + + + + + + + + Layout that will be rendered as the attribute's value. + + + + + Name of the attribute. + + + + + Determines wether or not this attribute will be Json encoded. + + + + + Indicates whether to escape non-ascii characters + + + + + Whether an attribute with empty value should be included in the output + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + + + + + + + + + + + + + + Option to include all properties from the log events + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include contents of the stack. + + + + + + + + + + + + + + Layout text. + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Condition expression. + + + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Default number of unique filter values to expect, will automatically increase if needed + + + + + Applies the configured action to the initial logevent that starts the timeout period. Used to configure that it should ignore all events until timeout. + + + + + Layout to be used to filter log messages. + + + + + Max number of unique filter values to expect simultaneously + + + + + Max length of filter values, will truncate if above limit + + + + + How long before a filter expires, and logging is accepted again + + + + + Default buffer size for the internal buffers + + + + + Reuse internal buffers, and doesn't have to constantly allocate new buffers + + + + + Append FilterCount to the when an event is no longer filtered + + + + + Insert FilterCount value into when an event is no longer filtered + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClipChopper/Libraries/ClipChopper.Logging/NLog/Extensions/IndentExceptionLayoutRenderer.cs b/ClipChopper/Libraries/ClipChopper.Logging/NLog/Extensions/IndentExceptionLayoutRenderer.cs new file mode 100644 index 0000000..e7840ea --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Logging/NLog/Extensions/IndentExceptionLayoutRenderer.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Concurrent; +using System.Linq; +using System.Text; +using NLog.Config; +using NLog.LayoutRenderers; + +namespace NLog.Extension +{ + /// + /// Renders exception starting from new line with short type exception name followed by message + /// and stacktrace (optionally). + /// If exception is logged more than once (catched, logged and re-thrown as inner), stack trace + /// is not written. + /// + /// + /// Original source: + /// (there is link to GitHub repository too). + /// + [LayoutRenderer("indent-exception")] + [ThreadAgnostic] + [ThreadSafe] + public sealed class IndentExceptionLayoutRenderer : LayoutRenderer + { + /// + /// Default stack trace indent in .NET is 3 space characters. + /// + private const string DefaultStackTraceIndent = " "; + + /// + /// Indent before exception type (default: 4 space characters). + /// + public string Indent { get; set; } = GenerateWhiteSpaceString(4); + + /// + /// Indent between each stack trace line (default: 8 space characters). + /// + public string StackTraceIndent { get; set; } = GenerateWhiteSpaceString(8); + + /// + /// Is written before exception type name (default: empty string). + /// + public string BeforeType { get; set; } = ""; + + /// + /// Is written after exception type name (default: empty string). + /// + public string AfterType { get; set; } = ""; + + /// + /// Separator between exception type and message (default: 1 space character). + /// + public string Separator { get; set; } = " "; + + /// + /// Log stack trace or not e.g. for console logger (default: true). + /// + public bool LogStack { get; set; } = true; + + /// + /// Is replaced newline characters in exception message or not (default: true). + /// + public bool ReplaceNewlinesInMessage { get; set; } = true; + + /// + /// Holds logged already exceptions just to skip stack logging. + /// + private static readonly ConcurrentQueue _loggedErrors = + new ConcurrentQueue(); + + + /// + /// Provides default initialization. + /// + public IndentExceptionLayoutRenderer() + { + } + + #region LayoutRenderer Overriden Methods + + /// + /// Appends formatted message with exception info. + /// + /// Source string builder to append message. + /// Specified parameter which contains exception info. + protected override void Append(StringBuilder builder, LogEventInfo logEvent) + { + Exception? ex = logEvent.Exception; + while (ex != null) + { + builder.Append( + $"{Indent}{BeforeType}{ex.GetType().FullName}{AfterType}{Separator}" + ); + + string exMessage = ReplaceNewlinesInMessage + ? ex.Message.Replace(Environment.NewLine, " ") + : ex.Message.Replace(Environment.NewLine, $"{Environment.NewLine}{Indent}"); + + builder.Append(exMessage); + + if (LogStack) + { + if (!_loggedErrors.Contains(ex) && ex.StackTrace != null) + { + builder.AppendLine(); + _loggedErrors.Enqueue(ex); + + builder.Append( + ex.StackTrace.Replace(DefaultStackTraceIndent, StackTraceIndent) + ); + } + + // Vasily Vasilyev: Do not know, why it is needed (took from source in GitHub). + if (_loggedErrors.Count > 33) + { + _loggedErrors.TryDequeue(out _); + _loggedErrors.TryDequeue(out _); + } + } + + ex = ex.InnerException; + if (ex != null) + { + builder.AppendLine(); + } + } + } + + #endregion + + /// + /// Generates string which contains only of specified white-spaces characters number. + /// + /// Number of white-spaces in returning string. + /// + /// String which contains only of specified white-spaces characters number. + /// + private static string GenerateWhiteSpaceString(int spaceNumber) + { + return string.Concat(Enumerable.Repeat(" ", spaceNumber)); + } + } +} diff --git a/ClipChopper/Libraries/ClipChopper.Logging/NLog/Extensions/ReplaceNewLinesFormatWrapperLayoutRenderer.cs b/ClipChopper/Libraries/ClipChopper.Logging/NLog/Extensions/ReplaceNewLinesFormatWrapperLayoutRenderer.cs new file mode 100644 index 0000000..e9e04ac --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Logging/NLog/Extensions/ReplaceNewLinesFormatWrapperLayoutRenderer.cs @@ -0,0 +1,52 @@ +using System; +using System.Text; +using NLog.Config; +using NLog.LayoutRenderers; +using NLog.LayoutRenderers.Wrappers; +using NLog.Layouts; + +namespace NLog.Extension +{ + /// + /// + /// + [LayoutRenderer("replace-newlines-withlayout")] + [ThreadAgnostic] + [ThreadSafe] + public sealed class ReplaceNewLinesFormatWrapperLayoutRenderer : WrapperLayoutRendererBase + { + private string _replacementString = " "; + + // Changed from + // public string Replacement { get; set; } + public Layout Replacement { get; set; } + + + public ReplaceNewLinesFormatWrapperLayoutRenderer() + { + // Changed from + // Replacement = " "; + Replacement = Layout.FromString(" "); + } + + // Override Append in order to render the replacement. + protected override void Append(StringBuilder builder, LogEventInfo logEvent) + { + // Render... + _replacementString = Replacement.Render(logEvent); + + // The base functionality of append is fine. + base.Append(builder, logEvent); + } + + // Called from base.Append(). + protected override string Transform(string text) + { + // Changed from + // return text.Replace(Environment.NewLine, Replacement); + + // Now just put in the rendered replacement string. + return text.Replace(Environment.NewLine, _replacementString); + } + } +} diff --git a/ClipChopper/Libraries/ClipChopper.Logging/NLog/NLogLoggerAdapter.cs b/ClipChopper/Libraries/ClipChopper.Logging/NLog/NLogLoggerAdapter.cs new file mode 100644 index 0000000..ae5cc72 --- /dev/null +++ b/ClipChopper/Libraries/ClipChopper.Logging/NLog/NLogLoggerAdapter.cs @@ -0,0 +1,115 @@ +using System; +using Acolyte.Assertions; +using NLog; + +namespace ClipChopper.Logging +{ + /// + /// Additional abstraction to avoid direct link with logger library. + /// + internal sealed class NLogLoggerAdapter : ILogger + { + /// + /// Concrete logger instance. + /// + /// Try to use logger as private static readonly field in code. + private readonly Logger _logger; + + + /// + /// Private constructor which could be called by create methods. + /// + /// Logger name to create. + /// + /// is null. + /// + /// + /// presents empty string. + /// + internal NLogLoggerAdapter(string loggerName) + { + loggerName.ThrowIfNullOrEmpty(nameof(loggerName)); + + _logger = LogManager.GetLogger(loggerName); + } + + #region ILogger Implementation + + /// + /// Prints header info. + /// + /// Additional message to print. + public void PrintHeader(string message) + { + message.ThrowIfNull(nameof(message)); + + TimeSpan offset = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow); + _logger.Info($"UTC offset is {offset}."); + + _logger.Info(message); + } + + /// + /// Prints footer info. + /// + /// Additional message to print. + public void PrintFooter(string message) + { + message.ThrowIfNull(nameof(message)); + + _logger.Info(message); + } + + /// + public void Debug(string message) + { + message.ThrowIfNull(nameof(message)); + + _logger.Debug(message); + } + + /// + public void Info(string message) + { + message.ThrowIfNull(nameof(message)); + + _logger.Info(message); + } + + /// + public void Warn(string message) + { + message.ThrowIfNull(nameof(message)); + + _logger.Warn(message); + } + + /// + public void Warn(Exception ex, string message) + { + ex.ThrowIfNull(nameof(ex)); + message.ThrowIfNull(nameof(message)); + + _logger.Warn(ex, message); + } + + /// + public void Error(string message) + { + message.ThrowIfNull(nameof(message)); + + _logger.Error(message); + } + + /// + public void Error(Exception ex, string message) + { + ex.ThrowIfNull(nameof(ex)); + message.ThrowIfNull(nameof(message)); + + _logger.Error(ex, message); + } + + #endregion + } +} diff --git a/ClipChopper/NuGet.Config b/ClipChopper/NuGet.Config new file mode 100644 index 0000000..2c70539 --- /dev/null +++ b/ClipChopper/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ClipChopper/global.json b/ClipChopper/global.json deleted file mode 100644 index 4db6a48..0000000 --- a/ClipChopper/global.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sdk": { - "version": "5.0", - "rollForward": "latestMajor", - "allowPrerelease": false - } -} \ No newline at end of file