Пример #1
0
        public static LoggerConfiguration WithConsoleLog(this LoggerConfiguration logger, NanoLoggerManager manager, IPropertyRetriever propertyRetriever, bool withDefaultConsoleLog = false)
        {
            if (withDefaultConsoleLog)
            {
                logger = logger
                         .WriteTo.Console(
                    outputTemplate: "{Timestamp} [{ColoredLogLevel}] (MachineName: {MachineName}) (Thread: {ThreadId}) {Message} {Exception}{NewLine}",
                    levelSwitch: new LoggingLevelSwitch());
            }
            else
            {
                var withConsoleLog = propertyRetriever.CheckFromCommandLine("withConsoleLog");

                if (withConsoleLog)
                {
                    var consoleMessageTemplate = propertyRetriever.RetrieveFromCommandLineOrEnvironment("consoleMessageTemplate", "consoleMessageTemplate", "{Timestamp} [{LogLevel}] (MachineName: {MachineName}) (Thread: {ThreadId}) {Message} {Exception}{NewLine}").Replace("{LogLevel}", "{ColoredLogLevel}");
                    manager.SetConsoleLoggingLevel(propertyRetriever.RetrieveFromCommandLineOrEnvironment("consoleMinimumLogEventLevel", "consoleMinimumLogEventLevel", LogLevel.None));
                    logger = logger
                             .WriteTo.Console(
                        outputTemplate: consoleMessageTemplate,
                        levelSwitch: manager.ConsoleLoggingLevelSwitch);
                }
            }

            return(logger);
        }
Пример #2
0
        public static LoggerConfiguration WithSeqLog(this LoggerConfiguration logger, NanoLoggerManager manager, IPropertyRetriever propertyRetriever)
        {
            var withSeqLog = propertyRetriever.CheckFromCommandLine("withSeqLog");

            if (withSeqLog)
            {
                var seqAddress = propertyRetriever.RetrieveFromCommandLineOrEnvironment("seqLogAddress", "seqLogAddress", null);
                var seqApiKey  = propertyRetriever.RetrieveFromCommandLineOrEnvironment("seqApiKey", "seqApiKey", null);
                manager.SetSeqLoggingLevel(propertyRetriever.RetrieveFromCommandLineOrEnvironment("seqMinimumLogEventLevel", "seqMinimumLogEventLevel", LogLevel.None));

                logger = logger
                         .WriteTo.Seq(
                    serverUrl: seqAddress,
                    apiKey: seqApiKey,
                    controlLevelSwitch: manager.SeqLoggingLevelSwitch);
            }

            return(logger);
        }
Пример #3
0
        public static LoggerConfiguration WithFileLog(this LoggerConfiguration logger, NanoLoggerManager manager, IPropertyRetriever propertyRetriever)
        {
            var withFileLog = propertyRetriever.CheckFromCommandLine("withFileLog");

            if (withFileLog)
            {
                var fileMessageTemplate = propertyRetriever.RetrieveFromCommandLineOrEnvironment("fileMessageTemplate", "fileMessageTemplate", "{Timestamp} [{LogLevel}] (MachineName: {MachineName}) (Thread: {ThreadId}) {Message} {Exception}{NewLine}");
                var fileRollingInterval = propertyRetriever.RetrieveFromCommandLineOrEnvironment("fileRollingInterval", "fileRollingInterval", RollingInterval.Hour);
                manager.SetFileLoggingLevel(propertyRetriever.RetrieveFromCommandLineOrEnvironment("fileMinimumLogEventLevel", "fileMinimumLogEventLevel", LogLevel.None));

                logger = logger
                         .WriteTo.File(
                    path: $"log\\log_{propertyRetriever.RetrieveServiceName()}_.txt",
                    levelSwitch: manager.FileLoggingLevelSwitch,
                    rollingInterval: fileRollingInterval,
                    outputTemplate: fileMessageTemplate,
                    shared: true);
            }

            return(logger);
        }