public static void ConfigureLogging(BaseSubOptions options) { var config = new LoggerConfiguration() .MinimumLevel.Verbose() .Destructure.UsingAttributes() .Destructure.ByTransforming <ReleaseAssetUpload>(asset => new { asset.FileName, asset.ContentType }); CreateDebugLogger(config); CreateConsoleInformationLogger(config, CONSOLE_INFO_TEMPLATE, _consoleTheme); CreateConsoleFullLogger(config, CONSOLE_FULL_TEMPLATE, _consoleTheme, options); if (!string.IsNullOrEmpty(options.LogFilePath)) { CreateFileLogger(config, options.LogFilePath, FILE_TEMPLATE); } Log.Logger = config.CreateLogger(); }
private static void CreateFiglet(BaseSubOptions options) { if (options.NoLogo) { return; } var version = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion; if (version.IndexOf('+') >= 0) { version = version.Substring(0, version.IndexOf('+')); } // The following ugly formats is to prevent incorrect indentation // detected by editorconfig formatters. const string shortFormat = "\n ____ ____ __ __\n" + " / ___| _ \\| \\/ |\n" + " | | _| |_) | |\\/| |\n" + " | |_| | _ <| | | |\n" + " \\____|_| \\_\\_| |_|\n" + "{0,21}\n"; const string longFormat = "\n ____ _ _ ____ _ __ __\n" + " / ___(_) |_| _ \\ ___| | ___ __ _ ___ ___| \\/ | __ _ _ __ __ _ __ _ ___ _ __\n" + " | | _| | __| |_) / _ \\ |/ _ \\/ _` / __|/ _ \\ |\\/| |/ _` | '_ \\ / _` |/ _` |/ _ \\ '__|\n" + " | |_| | | |_| _ < __/ | __/ (_| \\__ \\ __/ | | | (_| | | | | (_| | (_| | __/ |\n" + " \\____|_|\\__|_| \\_\\___|_|\\___|\\__,_|___/\\___|_| |_|\\__,_|_| |_|\\__,_|\\__, |\\___|_|\n" + " |___/\n" + "{0,87}\n"; if (GetConsoleWidth() > 87) { Log.Information(longFormat, version); } else { Log.Information(shortFormat, version); } }
private static void LogOptions(BaseSubOptions options) => Log.Debug("{@Options}", options);
private static void CreateConsoleFullLogger(LoggerConfiguration config, string consoleTemplate, ConsoleTheme consoleTheme, BaseSubOptions options) { config.WriteTo.Logger((config) => config .Filter.ByExcluding((logEvent) => logEvent.Level == LogEventLevel.Information) .Filter.ByExcluding((logEvent) => !options.Debug && logEvent.Level == LogEventLevel.Debug) .Filter.ByExcluding((logEvent) => !options.Verbose && logEvent.Level == LogEventLevel.Verbose) .WriteTo.Console( outputTemplate: consoleTemplate, standardErrorFromLevel: LogEventLevel.Warning, theme: consoleTheme)); }