private static bool TrySetupFileLogger()
        {
            try
            {
                var filenameBaseInfo = new DatadogEnvironmentFileLogSinkFactory.FilenameBaseInfo(ProductFamily, Product, ComponentGroup);
                if (DatadogEnvironmentFileLogSinkFactory.TryCreateNewFileLogSink(filenameBaseInfo,
                                                                                 ManagedLoaderLogGroupId,
                                                                                 preferredLogFileDirectory: null,
                                                                                 FileFormatOptions,
                                                                                 out FileLogSink fileLogSink))
                {
                    ILogSink logSink;
#pragma warning disable CS0162 // Unreachable code detected - intentional conditional using const bool
                    if (UseConsoleLogInAdditionToFileLog)
                    {
                        logSink = new AggregatedLogSink(SimpleConsoleLogSink.SingeltonInstance, fileLogSink);
                    }
                    else
                    {
                        logSink = fileLogSink;
                    }
#pragma warning restore CS0162 // Unreachable code detected

                    RedirectLogs(logSink, out s_logRedirections);
                    LogComposer.SetDebugLoggingEnabledBasedOnEnvironment();
                    return(true);
                }
            }
            catch
            { }

            return(false);
        }
Пример #2
0
        private static bool TrySetupFileLogger()
        {
            try
            {
                var filenameBaseInfo = new DatadogEnvironmentFileLogSinkFactory.FilenameBaseInfo(ProductFamily, Product, ComponentGroup);
                if (DatadogEnvironmentFileLogSinkFactory.TryCreateNewFileLogSink(filenameBaseInfo,
                                                                                 LoggingDemoLogGroupId,
                                                                                 preferredLogFileDirectory: null,
                                                                                 LogFileSizeBytes,
                                                                                 formatOptions: null,
                                                                                 out FileLogSink fileLogSink))
                {
                    RedirectLogs(fileLogSink, out s_logRedirections);
                    LogComposer.SetDebugLoggingEnabledBasedOnEnvironment();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                ConsoleWriteLine();
                ConsoleWriteLine($"Error setting up a file logger.");
                ConsoleWriteLine($"{ex}");
            }

            return(false);
        }
        private static bool TrySetupFileLogger(IProductConfiguration config)
        {
            try
            {
                var filenameBaseInfo = new DatadogEnvironmentFileLogSinkFactory.FilenameBaseInfo(ProductFamily, Product, ComponentGroup);
                if (DatadogEnvironmentFileLogSinkFactory.TryCreateNewFileLogSink(
                        filenameBaseInfo,
                        LoggingDemoLogGroupId,
                        config?.Log_PreferredLogFileDirectory,
                        LogFileSizeBytes,
                        FileFormatOptions,
                        out FileLogSink fileLogSink))
                {
                    RedirectLogs(fileLogSink, out _logRedirections);

                    if (config != null)
                    {
                        LogComposer.IsDebugLoggingEnabled = config.Log_IsDebugEnabled;
                    }
                    else
                    {
                        LogComposer.SetDebugLoggingEnabledBasedOnEnvironment();
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                ConsoleWriteLine();
                ConsoleWriteLine("Error setting up a file logger.");
                ConsoleWriteLine($"{ex}");
            }

            return(false);
        }