public ActiveFeatureFactory(IKernel kernel, IInstanceConfiguration instanceConfiguration, ILog log, ILoggingConfiguration loggingConfiguration)
 {
     _kernel = kernel;
     _instanceConfiguration = instanceConfiguration;
     _log = log;
     _loggingConfiguration = loggingConfiguration;
 }
Пример #2
0
 public Monitor(
     IDataCollector collector,
     IActivityProcessor processor,
     ILoggingConfiguration configuration,
     IMonitorBehaviorFactory behaviorFactory)
 {
     _applicationId = configuration.ApplicationId;
     _collector = collector;
     _processor = processor;
     _behaviorFactory = behaviorFactory;
 }
Пример #3
0
 public MonitorBehaviorFactory(ILoggingConfiguration configuration, IDomainContext context, IRulesCompiler compiler)
 {
     var application = context.Applications.Get(configuration.ApplicationId);
     var result = compiler.Compile(application.LoggingRules);
     if (!result.Success)
     {
         var messages = result.Errors.Select(x => "{0} ({1},{2})".Args(x.Message, x.Line, x.Column)).ToArray();
         throw new RulesCompilationException(String.Join(" | ", messages));
     }
     _rules = new List<IRule>(result.Rules);
 }
Пример #4
0
 public void SetUp()
 {
     _logger = new ConsoleOutLogger("InstallUtilTests", LogLevel.All, true, false, false, "yyyy-MM-dd hh:mm:ss");
     _folderFileSearcher = new FolderFileSearcher();
     _setupLogDirectory = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), "NMultiToolInstallUtilIntegrationTestsSetupLogs");
     if (!Directory.Exists(_setupLogDirectory)) Directory.CreateDirectory(_setupLogDirectory);            
     _stubLoggingConfiguration = MockRepository.GenerateStub<ILoggingConfiguration>();
     _stubLoggingConfiguration.LogDirectoryPath = _setupLogDirectory;
     _assemblyFileInfo = new FileInfo(typeof(InstallerExample).Assembly.Location);
     _includeFileSpecification = new List<string>() {_assemblyFileInfo.Name};
     _excludeFileSpecifications = new List<string>();
     if (File.Exists(InstallerExample.InstalledFile)) File.Delete(InstallerExample.InstalledFile);
     if (File.Exists(InstallerExample.UnInstalledFile)) File.Delete(InstallerExample.UnInstalledFile);
 }
        /// <summary>
        /// This configures Serilog with some defaults
        /// Such as adding ProcessID, Thread, AppDomain etc
        /// It is highly recommended that you keep/use this default in your own logging config customizations
        /// </summary>
        public static LoggerConfiguration MinimalConfiguration(
            this LoggerConfiguration logConfig,
            IHostingEnvironment hostingEnvironment,
            ILoggingConfiguration loggingConfiguration,
            IConfiguration configuration,
            out UmbracoFileConfiguration umbFileConfiguration)
        {
            global::Serilog.Debugging.SelfLog.Enable(msg => System.Diagnostics.Debug.WriteLine(msg));

            //Set this environment variable - so that it can be used in external config file
            //add key="serilog:write-to:RollingFile.pathFormat" value="%BASEDIR%\logs\log.txt" />
            Environment.SetEnvironmentVariable("BASEDIR", hostingEnvironment.MapPathContentRoot("/").TrimEnd("\\"), EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("UMBLOGDIR", loggingConfiguration.LogDirectory, EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("MACHINENAME", Environment.MachineName, EnvironmentVariableTarget.Process);

            logConfig.MinimumLevel.Verbose() //Set to highest level of logging (as any sinks may want to restrict it to Errors only)
            .Enrich.WithProcessId()
            .Enrich.WithProcessName()
            .Enrich.WithThreadId()
            .Enrich.WithProperty(AppDomainId, AppDomain.CurrentDomain.Id)
            .Enrich.WithProperty("AppDomainAppId", hostingEnvironment.ApplicationId.ReplaceNonAlphanumericChars(string.Empty))
            .Enrich.WithProperty("MachineName", Environment.MachineName)
            .Enrich.With <Log4NetLevelMapperEnricher>()
            .Enrich.FromLogContext();     // allows us to dynamically enrich

            //This is not optimal, but seems to be the only way if we do not make an Serilog.Sink.UmbracoFile sink all the way.
            var umbracoFileConfiguration = new UmbracoFileConfiguration(configuration);

            umbFileConfiguration = umbracoFileConfiguration;

            logConfig.WriteTo.UmbracoFile(
                path: umbracoFileConfiguration.GetPath(loggingConfiguration.LogDirectory),
                fileSizeLimitBytes: umbracoFileConfiguration.FileSizeLimitBytes,
                restrictedToMinimumLevel: umbracoFileConfiguration.RestrictedToMinimumLevel,
                rollingInterval: umbracoFileConfiguration.RollingInterval,
                flushToDiskInterval: umbracoFileConfiguration.FlushToDiskInterval,
                rollOnFileSizeLimit: umbracoFileConfiguration.RollOnFileSizeLimit,
                retainedFileCountLimit: umbracoFileConfiguration.RetainedFileCountLimit
                );

            return(logConfig);
        }
Пример #6
0
        private static void GenerateLogs(ILogger logger, ILoggingConfiguration loggingConfig)
        {
            Print("Default settings");
            GenerateLogs(logger);

            Print($"Changing log level of category=Thinktecture and provider=all to {LogLevel.Warning}");
            loggingConfig.SetLevel(LogLevel.Warning, "Thinktecture");
            GenerateLogs(logger);

            Print($"Changing log level of category=all and provider=Console to {LogLevel.Error}");
            loggingConfig.SetLevel(LogLevel.Error, null, "Console");
            GenerateLogs(logger);

            Print($"Changing log level of category=Thinktecture and provider=Console to {LogLevel.Critical}");
            loggingConfig.SetLevel(LogLevel.Critical, "Thinktecture", "Console");
            GenerateLogs(logger);

            Print("Resetting all settings, returning to defaults");
            loggingConfig.ResetLevel();
            GenerateLogs(logger);
        }
Пример #7
0
        /// <summary>
        /// Create and configure the logger
        /// </summary>
        public static IServiceCollection AddLogger(
            this IServiceCollection services,
            IHostingEnvironment hostingEnvironment,
            ILoggingConfiguration loggingConfiguration,
            IConfiguration configuration)
        {
            // Create a serilog logger
            var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration, configuration, out var umbracoFileConfig);

            services.AddSingleton(umbracoFileConfig);

            // This is nessasary to pick up all the loggins to MS ILogger.
            Log.Logger = logger.SerilogLog;

            // Wire up all the bits that serilog needs. We need to use our own code since the Serilog ext methods don't cater to our needs since
            // we don't want to use the global serilog `Log` object and we don't have our own ILogger implementation before the HostBuilder runs which
            // is the only other option that these ext methods allow.
            // I have created a PR to make this nicer https://github.com/serilog/serilog-extensions-hosting/pull/19 but we'll need to wait for that.
            // Also see : https://github.com/serilog/serilog-extensions-hosting/blob/dev/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs

            services.AddLogging(configure =>
            {
                configure.AddSerilog(logger.SerilogLog, false);
            });

            // This won't (and shouldn't) take ownership of the logger.
            services.AddSingleton(logger.SerilogLog);

            // Registered to provide two services...
            var diagnosticContext = new DiagnosticContext(logger.SerilogLog);

            // Consumed by e.g. middleware
            services.AddSingleton(diagnosticContext);

            // Consumed by user code
            services.AddSingleton <IDiagnosticContext>(diagnosticContext);
            services.AddSingleton(loggingConfiguration);

            return(services);
        }
Пример #8
0
        /// <summary>
        /// Prepares the logging service for recording to logging endpoints
        /// </summary>
        /// <param name="loggingConfiguration">The parameters to record log records with</param>
        public EasyLoggerService(ILoggingConfiguration loggingConfiguration)
        {
            Settings = loggingConfiguration;

            // Prepare loggers
            Endpoints = new List <ILoggerEndpoint>();

            if (Settings.UseTextLogger)
            {
                Endpoints.Add(new TextLogger(Settings));
            }

            if (Settings.UseJsonLogger)
            {
                Endpoints.Add(new JsonLogger(Settings));
            }

            if (Settings.UseSqlLogger)
            {
                Endpoints.Add(new SqlLogger(Settings));
            }
        }
Пример #9
0
 /// <summary>
 /// Logger configuration
 /// </summary>
 public FluentApplicationBootstrapConfiguration AddLoggerConfiguration(ILoggingConfiguration loggerConfiguration)
 {
     LoggerConfiguration = loggerConfiguration;
     return(this);
 }
Пример #10
0
 public static void InitializeLogging(ILoggingConfiguration config)
 {
     InitializeLogging(config, null, null);
 }
Пример #11
0
 public LogMediatrRequest(ILogger <LogMediatrRequest <TRequest> > logger,
                          ILoggingConfiguration loggingConfiguration)
 {
     this.logger = logger;
     this.loggingConfiguration = loggingConfiguration;
 }
 /// <summary>
 /// Initialises a new instance of the <see cref="LoggingConfiguration"/> class.
 /// </summary>
 /// <param name="logger">The previously set <see cref="ILoggingConfiguration"/>.</param>
 public LoggingConfiguration(ILoggingConfiguration logger)
     : this(logger.Logger)
 {
     this.LoggingConfigurationInstance = logger;
 }
Пример #13
0
 public EasyWebLogProvider(ILoggingConfiguration loggingConfiguration, LogLevel[] logLevels)
 {
     LoggingConfiguration = loggingConfiguration;
     LogLevels            = logLevels;
 }
Пример #14
0
        /// <nodoc />
        public LoggingConfiguration(ILoggingConfiguration template, PathRemapper pathRemapper)
            : base(template)
        {
            Contract.Assume(template != null);
            Contract.Assume(pathRemapper != null);

            LogsDirectory           = pathRemapper.Remap(template.LogsDirectory);
            RedirectedLogsDirectory = pathRemapper.Remap(template.RedirectedLogsDirectory);
            LogPrefix                               = template.LogPrefix;
            Log                                     = pathRemapper.Remap(template.Log);
            ErrorLog                                = pathRemapper.Remap(template.ErrorLog);
            WarningLog                              = pathRemapper.Remap(template.WarningLog);
            LogExecution                            = template.LogExecution;
            LogPackedExecution                      = template.LogPackedExecution;
            ExecutionLog                            = pathRemapper.Remap(template.ExecutionLog);
            StoreFingerprints                       = template.StoreFingerprints;
            SaveFingerprintStoreToLogs              = template.SaveFingerprintStoreToLogs;
            FingerprintStoreMode                    = template.FingerprintStoreMode;
            FingerprintStoreMaxEntryAgeMinutes      = template.FingerprintStoreMaxEntryAgeMinutes;
            FingerprintStoreBulkLoad                = template.FingerprintStoreBulkLoad;
            FingerprintsLogDirectory                = pathRemapper.Remap(template.FingerprintsLogDirectory);
            ExecutionFingerprintStoreLogDirectory   = pathRemapper.Remap(template.ExecutionFingerprintStoreLogDirectory);
            CacheLookupFingerprintStoreLogDirectory = pathRemapper.Remap(template.CacheLookupFingerprintStoreLogDirectory);
            HistoricMetadataCacheLogDirectory       = pathRemapper.Remap(template.HistoricMetadataCacheLogDirectory);
            EngineCacheLogDirectory                 = pathRemapper.Remap(template.EngineCacheLogDirectory);
            EngineCacheCorruptFilesLogDirectory     = pathRemapper.Remap(template.EngineCacheCorruptFilesLogDirectory);
            CustomLog                               = new Dictionary <AbsolutePath, (IReadOnlyList <int>, EventLevel?)>();
            foreach (var kv in template.CustomLog)
            {
                CustomLog.Add(pathRemapper.Remap(kv.Key), kv.Value);
            }

            CustomLogEtwKinds = new Dictionary <AbsolutePath, string>();
            foreach (var kv in template.CustomLogEtwKinds)
            {
                CustomLogEtwKinds.Add(pathRemapper.Remap(kv.Key), kv.Value);
            }

            NoLog              = new List <int>(template.NoLog);
            NoExecutionLog     = new List <int>(template.NoExecutionLog);
            Diagnostic         = template.Diagnostic;
            ConsoleVerbosity   = template.ConsoleVerbosity;
            FileVerbosity      = template.FileVerbosity;
            LogCounters        = template.LogCounters;
            LogStats           = template.LogStats;
            EnableAsyncLogging = template.EnableAsyncLogging;
            StatsLog           = pathRemapper.Remap(template.StatsLog);
            StatsPrfLog        = pathRemapper.Remap(template.StatsPrfLog);
            EventSummaryLog    = pathRemapper.Remap(template.EventSummaryLog);
            Environment        = template.Environment;
            RemoteTelemetry    = template.RemoteTelemetry;
            TraceInfo          = new Dictionary <string, string>();
            foreach (var kv in template.TraceInfo)
            {
                TraceInfo.Add(kv.Key, kv.Value);
            }

            Color                            = template.Color;
            AnimateTaskbar                   = template.AnimateTaskbar;
            RelatedActivityId                = template.RelatedActivityId;
            LogsToRetain                     = template.LogsToRetain;
            FancyConsole                     = template.FancyConsole;
            FancyConsoleMaxStatusPips        = template.FancyConsoleMaxStatusPips;
            SubstSource                      = pathRemapper.Remap(template.SubstSource);
            SubstTarget                      = pathRemapper.Remap(template.SubstTarget);
            DisableLoggedPathTranslation     = template.DisableLoggedPathTranslation;
            LogStatus                        = template.LogStatus;
            LogTracer                        = template.LogTracer;
            StatusFrequencyMs                = template.StatusFrequencyMs;
            StatusLog                        = pathRemapper.Remap(template.StatusLog);
            TraceLog                         = pathRemapper.Remap(template.TraceLog);
            CacheMissLog                     = pathRemapper.Remap(template.CacheMissLog);
            DevLog                           = pathRemapper.Remap(template.DevLog);
            RpcLog                           = pathRemapper.Remap(template.RpcLog);
            PipOutputLog                     = pathRemapper.Remap(template.PipOutputLog);
            FailPipOnFileAccessError         = template.FailPipOnFileAccessError;
            LogMemory                        = template.LogMemory;
            ReplayWarnings                   = template.ReplayWarnings;
            UseCustomPipDescriptionOnConsole = template.UseCustomPipDescriptionOnConsole;
            CacheMissAnalysisOption          = new CacheMissAnalysisOption(
                template.CacheMissAnalysisOption.Mode,
                new List <string>(template.CacheMissAnalysisOption.Keys),
                pathRemapper.Remap(template.CacheMissAnalysisOption.CustomPath));
            CacheMissDiffFormat = template.CacheMissDiffFormat;
            CacheMissBatch      = template.CacheMissBatch;
            OptimizeConsoleOutputForAzureDevOps    = template.OptimizeConsoleOutputForAzureDevOps;
            InvocationExpandedCommandLineArguments = template.InvocationExpandedCommandLineArguments;
            OptimizeProgressUpdatingForAzureDevOps = template.OptimizeProgressUpdatingForAzureDevOps;
            OptimizeVsoAnnotationsForAzureDevOps   = template.OptimizeVsoAnnotationsForAzureDevOps;
            AriaIndividualMessageSizeLimitBytes    = template.AriaIndividualMessageSizeLimitBytes;
            MaxNumPipTelemetryBatches     = template.MaxNumPipTelemetryBatches;
            DumpFailedPips                = template.DumpFailedPips;
            DumpFailedPipsLogLimit        = template.DumpFailedPipsLogLimit;
            DumpFailedPipsWithDynamicData = template.DumpFailedPipsWithDynamicData;
            LogCachedPipOutputs           = template.LogCachedPipOutputs;
        }
 /// <summary>
 /// Initialises a new instance of the <see cref="HostAddressConfiguration"/> class.
 /// </summary>
 /// <param name="loggingConfiguration">Previously set logging information.</param>
 /// <param name="hostAddress">The address the <see cref="IServiceBus"/> will be accessible from.</param>
 public HostAddressConfiguration(ILoggingConfiguration loggingConfiguration, Uri hostAddress)
     : base(loggingConfiguration)
 {
     this.HostAddress = hostAddress;
 }
 public ApiClientFactory(ILoginCache loginCache, IProgram program, ILoggingConfiguration config)
 {
     LoginCache = loginCache;
     productHeader = program.ProductHeader;
     config.Configure();
 }
Пример #17
0
 public TextLogger(ILoggingConfiguration loggingConfiguration) : base(loggingConfiguration)
 {
     Settings = loggingConfiguration;
 }
Пример #18
0
 /// <summary>
 /// Initialises a new instance of the <see cref="HostAddressConfiguration"/> class.
 /// </summary>
 /// <param name="loggingConfiguration">Previously set logging information.</param>
 /// <param name="hostAddress">The address the <see cref="IServiceBus"/> will be accessible from.</param>
 public HostAddressConfiguration(ILoggingConfiguration loggingConfiguration, Uri hostAddress)
     : base(loggingConfiguration)
 {
     this.HostAddress = hostAddress;
 }
 public ActiveFeatureFactory(IKernel kernel, IInstanceConfiguration instanceConfiguration, ILog log, ILoggingConfiguration loggingConfiguration, TextWriter output)
 {
     _kernel = kernel;
     _instanceConfiguration = instanceConfiguration;
     _log = log;
     _loggingConfiguration = loggingConfiguration;
     _output = output;
 }
Пример #20
0
 /// <summary>
 /// Helper to compute whether pip stderr/stdout warnings are promoted to errors
 /// </summary>
 public static bool ArePipWarningsPromotedToErrors(ILoggingConfiguration loggingConfiguration)
 {
     return((loggingConfiguration.TreatWarningsAsErrors && (loggingConfiguration.WarningsNotAsErrors.Count == 0 || !loggingConfiguration.WarningsNotAsErrors.Contains((int)EventId.PipProcessWarning))) ||
            loggingConfiguration.WarningsAsErrors.Contains((int)EventId.PipProcessWarning));
 }
Пример #21
0
 public InstallUtil(ILoggingConfiguration loggingConfiguration,IFolderFileSearcher folderFileSearcher,ILog logger)
 {
     _loggingConfiguration = loggingConfiguration;
     _folderFileSearcher = folderFileSearcher;
     _logger = logger;
 }
Пример #22
0
 public EasyWebLogger(ILoggingConfiguration loggingConfiguration, LogLevel[] logLevels) : base(loggingConfiguration)
 {
     LogLevels = logLevels;
 }
 /// <summary>
 /// Initialises a new instance of the <see cref="LoggingConfiguration"/> class.
 /// </summary>
 /// <param name="logger">The previously set <see cref="ILoggingConfiguration"/>.</param>
 public LoggingConfiguration(ILoggingConfiguration logger) : this(logger.Logger)
 {
     this.LoggingConfigurationInstance = logger;
 }
Пример #24
0
        /// <summary>
        /// Sets the address the <see cref="IServiceBus"/> will be accessible from.
        /// </summary>
        /// <param name="loggingConfiguration">The previously set logging configuration.</param>
        /// <param name="address">The address the <see cref="IServiceBus"/> will be accessible from.</param>
        /// <returns>The host address configuration.</returns>
        public static IHostAddressConfiguration WithHostAddress(this ILoggingConfiguration loggingConfiguration, Uri address)
        {
            Argument.CannotBeNull(address, "hostAddress", "The host address for the service bus cannot be null.");

            return(new HostAddressConfiguration(loggingConfiguration, address));
        }
 public LogMediatrResponse(ILogger <LogMediatrResponse <TRequest, TResponse> > logger,
                           ILoggingConfiguration loggingConfiguration)
 {
     this.logger = logger;
     this.loggingConfiguration = loggingConfiguration;
 }
Пример #26
0
 public InstallUtil(ILoggingConfiguration loggingConfiguration, IFolderFileSearcher folderFileSearcher, ILog logger)
 {
     _loggingConfiguration = loggingConfiguration;
     _folderFileSearcher   = folderFileSearcher;
     _logger = logger;
 }
Пример #27
0
 /// <summary>
 /// <see cref="ILoggingConfiguration.ReplayWarnings"/>
 /// </summary>
 /// <remarks>
 /// Defaults to true.
 /// </remarks>
 public static bool ReplayWarnings(this ILoggingConfiguration loggingConfiguration) => loggingConfiguration.ReplayWarnings ?? true;
Пример #28
0
        /// <summary>
        /// Initiate logging in database
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="levels"></param>
        public NLogger(DatabaseLoggingConfiguration configuration, params LogLevel[] levels)
        {
            LoggingConfiguration = configuration;

            using (var connection = new SqlConnection(configuration.ConnectionString))
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction($"Create{configuration.TableName}"))
                {
                    var sql =
                        $@"
                        IF NOT EXISTS 
                        (	
                            SELECT * 
                            FROM sys.tables t 
                            WHERE t.name = '{configuration.TableName}'
                        )
                        BEGIN
                            CREATE TABLE [{configuration.TableName}]
                            (
                                [Id] INT IDENTITY(1,1) NOT NULL, 
                                [CreatedOn] DATETIME2(7) NOT NULL, 
                                [Level] NVARCHAR(MAX) NULL,
                                [ErrorGroup] NVARCHAR(MAX) NULL,
                                [ErrorCode] NVARCHAR(MAX) NULL,
                                [Origin] NVARCHAR(MAX) NULL,
                                [ProcessName] NVARCHAR(MAX) NULL,
                                [Action] NVARCHAR(MAX) NULL,
                                [ActionFilePath] NVARCHAR(MAX) NULL,
                                [ActionSourceLineNumber] NVARCHAR(MAX) NULL,
                                [Message] NVARCHAR(MAX) NULL,
                                [ExceptionMessage] NVARCHAR(MAX) NULL,
                                [UserIdentifier] NVARCHAR(MAX) NULL,
                                [Payload] NVARCHAR(MAX) NULL
                                CONSTRAINT [PK_{configuration.TableName}] PRIMARY KEY CLUSTERED 
                                (
	                                [Id] ASC
                                )WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
                            ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
                        
                            ALTER TABLE [{configuration.TableName}] ADD CONSTRAINT [DF_{configuration.TableName}_CreateOn]  DEFAULT (getutcdate()) FOR [CreatedOn]; 
                        END
                    ";

                    var command = new SqlCommand(sql, connection, transaction);
                    command.ExecuteNonQuery();
                    transaction.Commit();
                }
            }

            var dbTarget = new DatabaseTarget("database")
            {
                DBHost      = configuration.Host,
                DBDatabase  = configuration.Database,
                DBPassword  = configuration.Password,
                DBUserName  = configuration.Username,
                DBProvider  = configuration.DataProvider.GetDescription(),
                CommandText = $@"
                    insert into {configuration.TableName} (
                        Level,
                        ErrorGroup,
                        ErrorCode,
                        Origin,
                        Action,
                        ProcessName,
                        ActionFilePath,
                        ActionSourceLineNumber,
                        Message,
                        ExceptionMessage,
                        UserIdentifier,
                        Payload
                    ) values (
                        @Level,
                        @ErrorGroup,
                        @ErrorCode,
                        @Origin,
                        @Action,
                        @ProcessName,
                        @ActionFilePath,
                        @ActionSourceLineNumber,
                        @Message,
                        @ExceptionMessage,
                        @UserIdentifier,
                        @Payload
                    );"
            };

            dbTarget.Parameters.Add(new DatabaseParameterInfo("@level", Layout.FromString(@"${event-properties:item=Level}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@errorGroup", Layout.FromString(@"${event-properties:item=ErrorGroup}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@errorCode", Layout.FromString(@"${event-properties:item=ErrorCode}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@origin", Layout.FromString(@"${event-properties:item=Origin}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@action", Layout.FromString(@"${event-properties:item=Action}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@processName", Layout.FromString(@"${event-properties:item=ProcessName}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@actionFilePath", Layout.FromString(@"${event-properties:item=ActionFilePath}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@actionSourceLineNumber", Layout.FromString(@"${event-properties:item=ActionSourceLineNumber}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@message", Layout.FromString(@"${event-properties:item=Message}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@exceptionMessage", Layout.FromString(@"${event-properties:item=ExceptionMessage}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@userIdentifier", Layout.FromString(@"${event-properties:item=UserIdentifier}")));
            dbTarget.Parameters.Add(new DatabaseParameterInfo("@payload", Layout.FromString(@"${event-properties:item=Payload}")));

            InitTarget(dbTarget, levels?.ToList());
        }
Пример #29
0
 public Log4NetManager(ILoggingConfiguration configuration)
 {
     _configuration = configuration;
 }
Пример #30
0
        private static Optional <CompositeGraphFingerprint> GenerateHash(
            LoggingContext loggingContext,
            IStartupConfiguration startUpConfig,
            IConfiguration config,
            PathTable pathTable,
            IEvaluationFilter partialEvaluationData,
            FileContentTable fileContentTable,
            string commitId,
            EngineTestHooksData testHooks)
        {
            ILayoutConfiguration  layout  = config.Layout;
            ILoggingConfiguration logging = config.Logging;
            var fingerprintTextElements   = new List <(string, string)>();

            using (var hasher = new CoreHashingHelper(recordFingerprintString: true))
            {
                CompositeGraphFingerprint fingerprint = CompositeGraphFingerprint.Zero;

                AddInt(hasher, "version", GraphFingerprintVersion);

                using (var qualifierHasher = new CoreHashingHelper(recordFingerprintString: false))
                {
                    foreach (string qualifier in startUpConfig.QualifierIdentifiers.OrderBy(q => q))
                    {
                        AddText(qualifierHasher, "qualifier", qualifier);
                    }

                    fingerprint.QualifierHash = qualifierHasher.GenerateHash();
                    AddFingerprint(hasher, "Qualifiers", fingerprint.QualifierHash);
                }

                if (partialEvaluationData != null && partialEvaluationData.CanPerformPartialEvaluation)
                {
                    using (var evaluationFilterHasher = new CoreHashingHelper(recordFingerprintString: false))
                    {
                        foreach (string value in partialEvaluationData.ValueNamesToResolveAsStrings.OrderBy(v => v))
                        {
                            AddText(evaluationFilterHasher, "valueName", value);
                        }

                        foreach (string value in partialEvaluationData.ValueDefinitionRootsToResolveAsStrings.OrderBy(v => v))
                        {
                            AddText(evaluationFilterHasher, "valuePath", value);
                        }

                        foreach (string value in partialEvaluationData.ModulesToResolveAsStrings.OrderBy(v => v))
                        {
                            AddText(evaluationFilterHasher, "moduleName", value);
                        }

                        fingerprint.FilterHash = evaluationFilterHasher.GenerateHash();
                        AddFingerprint(hasher, "Values", fingerprint.FilterHash);
                    }
                }

                // These paths get embedded in the result of evaluation. So if any change we must re-evaluate
                AddText(hasher, "ObjectDirectoryPath", layout.ObjectDirectory.IsValid ? layout.ObjectDirectory.ToString(pathTable) : "::null::");
                AddText(hasher, "TempDirectoryPath", layout.TempDirectory.IsValid ? layout.TempDirectory.ToString(pathTable) : "::null::");
                AddText(hasher, "SourceDirectoryPath", layout.SourceDirectory.IsValid ? layout.SourceDirectory.ToString(pathTable) : "::null::");

                // All paths in the graph are relative to 'substTarget' (hence, 'substTarget' must be a part of the fingerprint, but 'substSource' need not be).
                AddText(hasher, "substTarget", logging.SubstTarget.IsValid ? logging.SubstTarget.ToString(pathTable) : "::null::");
                AddText(hasher, "IsCompressed", config.Engine.CompressGraphFiles ? "true" : "false");
                AddText(hasher, "IsSkipHashSourceFile", config.Schedule.SkipHashSourceFile ? "true" : "false");

                // Pip static fingerprints are not always computed because computing them slows down the graph construction by 10%-13%.
                // Thus, the pip graph may and may not contain pip static fingerprints. To avoid unexpected result due to graph cache hit,
                // we temporarily add the option for computing pip static fingerprints as part of our graph fingerprint until the fingerprints
                // are always computed; see Task 1291638.
                AddText(hasher, "ComputePipStaticFingerprints", config.Schedule.ComputePipStaticFingerprints.ToString());

                if (config.Schedule.ComputePipStaticFingerprints)
                {
                    // Pip static fingerprints are part of the graph and include the extra fingerprint salts.
                    // Thus, when pip static fingerprints are computed, any change to the salt will invalidate the graph because
                    // the pip static fingerprints will no longer be valid. Reusing the graph when the salt changes can result in
                    // underbuild.
                    var extraFingerprintSalts = new ExtraFingerprintSalts(
                        config,
                        PipFingerprintingVersion.TwoPhaseV2,
                        config.Cache.CacheSalt ?? string.Empty,
                        new Scheduler.DirectoryMembershipFingerprinterRuleSet(config, pathTable.StringTable).ComputeSearchPathToolsHash());

                    AddFingerprint(hasher, "ExtraFingerprintSalts", extraFingerprintSalts.CalculatedSaltsFingerprint);
                }

                // Config files
                // Caution: Including the content hash of the config file is how changes to the default pip filter
                // invalidate a cached graph. If the config file content hash is removed, the values that get
                // evaluated because of it must be reflected in the values passed in to this method.
                using (var configHasher = new CoreHashingHelper(recordFingerprintString: false))
                {
                    var configFiles = new List <AbsolutePath> {
                        startUpConfig.ConfigFile
                    };

                    try
                    {
                        foreach (var configPath in configFiles
                                 .Select(path => path.ToString(pathTable))
                                 .OrderBy(c => c, StringComparer.OrdinalIgnoreCase))
                        {
                            AddContentHash(
                                configHasher,
                                configPath.ToUpperInvariant(),
                                fileContentTable.GetAndRecordContentHashAsync(configPath)
                                .GetAwaiter()
                                .GetResult()
                                .VersionedFileIdentityAndContentInfo.FileContentInfo.Hash);
                        }

                        fingerprint.ConfigFileHash = configHasher.GenerateHash();
                        AddFingerprint(hasher, "ConfigFiles", fingerprint.ConfigFileHash);
                    }
                    catch (BuildXLException ex)
                    {
                        return(LogAndReturnFailure(ex));
                    }
                }

                if (!string.IsNullOrEmpty(commitId))
                {
                    using (var commitHasher = new CoreHashingHelper(recordFingerprintString: false))
                    {
                        commitHasher.Add("Commit", commitId);
                        fingerprint.BuildEngineHash = commitHasher.GenerateHash();
                    }

                    AddFingerprint(hasher, "BuildEngine", fingerprint.BuildEngineHash);
                }
                else
                {
                    // BuildXL assemblies. This will invalidate the cached graph if build files change
                    // or if the serialization format changes.
                    try
                    {
                        Action <string, ContentHash> handleBuildFileAndHash = (buildFile, buildFileHash) =>
                        {
                            // Directly add to fingerprint elements for logging, but the hash is represented in the build engine hash
                            fingerprintTextElements.Add((buildFile, buildFileHash.ToString()));
                        };

                        var deployment = testHooks?.AppDeployment ?? AppDeployment.ReadDeploymentManifestFromRunningApp();
                        fingerprint.BuildEngineHash = deployment.ComputeContentHashBasedFingerprint(fileContentTable, handleBuildFileAndHash);
                        AddFingerprint(hasher, "BuildEngine", fingerprint.BuildEngineHash);
                    }
                    catch (BuildXLException ex)
                    {
                        Tracing.Logger.Log.FailedToComputeHashFromDeploymentManifest(loggingContext);
                        Tracing.Logger.Log.FailedToComputeHashFromDeploymentManifestReason(loggingContext, ex.Message);
                        return(default(Optional <CompositeGraphFingerprint>));
                    }
                }

                AddText(hasher, "HostOS", startUpConfig.CurrentHost.CurrentOS.ToString());
                AddText(hasher, "HostCpuArchitecture", startUpConfig.CurrentHost.CpuArchitecture.ToString());
                AddText(hasher, "HostIsElevated", CurrentProcess.IsElevated.ToString());

                var salt = string.Empty;

                if (testHooks?.GraphFingerprintSalt != null)
                {
                    salt += testHooks.GraphFingerprintSalt.Value.ToString();
                }

                salt += EngineEnvironmentSettings.DebugGraphFingerprintSalt;

                if (!string.IsNullOrEmpty(salt))
                {
                    hasher.Add("GraphFingerprintSalt", salt);
                }

                fingerprint.OverallFingerprint = new ContentFingerprint(hasher.GenerateHash());
                Tracing.Logger.Log.ElementsOfConfigurationFingerprint(
                    loggingContext,
                    fingerprint.OverallFingerprint.ToString(),
                    string.Join(Environment.NewLine, fingerprintTextElements.Select(kvp => "\t" + kvp.Item1 + " : " + kvp.Item2)));

                return(new Optional <CompositeGraphFingerprint>(fingerprint));
            }

            // Local functions
            void AddInt(CoreHashingHelper hasher, string key, int value)
            {
                hasher.Add(key, value);
                fingerprintTextElements.Add(
                    (key, value.ToString(CultureInfo.InvariantCulture)));
            }

            void AddText(CoreHashingHelper hasher, string key, string value)
            {
                hasher.Add(key, value);
                fingerprintTextElements.Add((key, value));
            }

            void AddFingerprint(CoreHashingHelper hasher, string key, Fingerprint value)
            {
                hasher.Add(key, value);
                fingerprintTextElements.Add((key, value.ToString()));
            }

            void AddContentHash(CoreHashingHelper hasher, string key, ContentHash value)
            {
                hasher.Add(key, value);
                fingerprintTextElements.Add((key, value.ToString()));
            }
        }
Пример #31
0
 public LoggerFactory(ILoggingConfiguration config)
 {
     this.config = config;
 }
Пример #32
0
        public static ILoggerManager GetLoggingService(ILoggingConfiguration loggingConfiguration)
        {
            var config = new NLog.Config.LoggingConfiguration();

            LogLevel minLogLevel = LogLevel.Error;

            switch (loggingConfiguration.LogLevel)
            {
            case Types.Enums.LogLevel.Info:
                minLogLevel = LogLevel.Info;
                break;

            case Types.Enums.LogLevel.Trace:
                minLogLevel = LogLevel.Trace;
                break;

            case Types.Enums.LogLevel.Debug:
                minLogLevel = LogLevel.Debug;
                break;

            case Types.Enums.LogLevel.Warn:
                minLogLevel = LogLevel.Warn;
                break;

            case Types.Enums.LogLevel.Error:
                minLogLevel = LogLevel.Error;
                break;

            case Types.Enums.LogLevel.Fatal:
                minLogLevel = LogLevel.Fatal;
                break;
            }

            var logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = "log.txt",
                DeleteOldFileOnStartup = true,
            };

            if (loggingConfiguration.LogVerbosity == LogVerbosity.Quit)
            {
                logfile.Layout =
                    "Local-Date=${longdate}|Level=${level}|Log-Message=${message}|Error-Message=${event-context:item=error-message}";
            }
            else if (loggingConfiguration.LogVerbosity == LogVerbosity.Diagnostic)
            {
                logfile.Layout =
                    "Local-Date=${longdate}|Level=${level}|Log-Message=${message}|Error-Source=${event-context:item=error-source}|Error-Class=${event-context:item=error-class}|Error-Method=${event-context:item=error-method}|Error-Message=${event-context:item=error-message}|Inner-Error-Message=${event-context:item=inner-error-message}";
            }
            else
            {
                logfile.Layout =
                    "Local-Date=${longdate}|Level=${level}|Log-Message=${message}|Error-Source=${event-context:item=error-source}|Error-Class=${event-context:item=error-class}|Error-Method=${event-context:item=error-method}|Error-Message=${event-context:item=error-message}|Inner-Error-Message=${event-context:item=inner-error-message}|Stack-Trace=${event-context:item=stack-trace}";
            }

            config.AddRule(minLogLevel, LogLevel.Fatal, logfile);

            // Apply config
            NLog.LogManager.Configuration = config;

            ConfigurationItemFactory.Default.LayoutRenderers
            .RegisterDefinition("utc_date", typeof(UtcDateRenderer));

            if (!loggingConfiguration.IsLoggingEnabled)
            {
                LogManager.GlobalThreshold = LogLevel.Off;
            }

            ILoggerManager logger = (ILoggerManager)NLog.LogManager.GetLogger("NLogLogger", typeof(LoggerManager));

            return(logger);
        }
Пример #33
0
        /// <nodoc />
        public LoggingConfiguration(ILoggingConfiguration template, PathRemapper pathRemapper)
            : base(template)
        {
            Contract.Assume(template != null);
            Contract.Assume(pathRemapper != null);

            LogsDirectory           = pathRemapper.Remap(template.LogsDirectory);
            RedirectedLogsDirectory = pathRemapper.Remap(template.RedirectedLogsDirectory);
            LogPrefix            = template.LogPrefix;
            Log                  = pathRemapper.Remap(template.Log);
            ErrorLog             = pathRemapper.Remap(template.ErrorLog);
            WarningLog           = pathRemapper.Remap(template.WarningLog);
            LogExecution         = template.LogExecution;
            ExecutionLog         = pathRemapper.Remap(template.ExecutionLog);
            StoreFingerprints    = template.StoreFingerprints;
            FingerprintStoreMode = template.FingerprintStoreMode;
            FingerprintStoreMaxEntryAgeMinutes      = template.FingerprintStoreMaxEntryAgeMinutes;
            FingerprintsLogDirectory                = pathRemapper.Remap(template.FingerprintsLogDirectory);
            ExecutionFingerprintStoreLogDirectory   = pathRemapper.Remap(template.ExecutionFingerprintStoreLogDirectory);
            CacheLookupFingerprintStoreLogDirectory = pathRemapper.Remap(template.CacheLookupFingerprintStoreLogDirectory);
            HistoricMetadataCacheLogDirectory       = pathRemapper.Remap(template.HistoricMetadataCacheLogDirectory);
            EngineCacheLogDirectory             = pathRemapper.Remap(template.EngineCacheLogDirectory);
            EngineCacheCorruptFilesLogDirectory = pathRemapper.Remap(template.EngineCacheCorruptFilesLogDirectory);
            CustomLog = new Dictionary <AbsolutePath, IReadOnlyList <int> >();
            foreach (var kv in template.CustomLog)
            {
                CustomLog.Add(pathRemapper.Remap(kv.Key), kv.Value);
            }

            CustomLogEtwKinds = new Dictionary <AbsolutePath, string>();
            foreach (var kv in template.CustomLogEtwKinds)
            {
                CustomLogEtwKinds.Add(pathRemapper.Remap(kv.Key), kv.Value);
            }

            NoLog              = new List <int>(template.NoLog);
            NoExecutionLog     = new List <int>(template.NoExecutionLog);
            Diagnostic         = template.Diagnostic;
            ConsoleVerbosity   = template.ConsoleVerbosity;
            FileVerbosity      = template.FileVerbosity;
            LogCounters        = template.LogCounters;
            LogStats           = template.LogStats;
            EnableAsyncLogging = template.EnableAsyncLogging;
            StatsLog           = pathRemapper.Remap(template.StatsLog);
            EventSummaryLog    = pathRemapper.Remap(template.EventSummaryLog);
            Environment        = template.Environment;
            RemoteTelemetry    = template.RemoteTelemetry;
            TraceInfo          = new Dictionary <string, string>();
            foreach (var kv in template.TraceInfo)
            {
                TraceInfo.Add(kv.Key, kv.Value);
            }

            Color                            = template.Color;
            AnimateTaskbar                   = template.AnimateTaskbar;
            RelatedActivityId                = template.RelatedActivityId;
            LogsToRetain                     = template.LogsToRetain;
            FancyConsole                     = template.FancyConsole;
            FancyConsoleMaxStatusPips        = template.FancyConsoleMaxStatusPips;
            SubstSource                      = pathRemapper.Remap(template.SubstSource);
            SubstTarget                      = pathRemapper.Remap(template.SubstTarget);
            DisableLoggedPathTranslation     = template.DisableLoggedPathTranslation;
            LogStatus                        = template.LogStatus;
            StatusFrequencyMs                = template.StatusFrequencyMs;
            StatusLog                        = pathRemapper.Remap(template.StatusLog);
            CacheMissLog                     = pathRemapper.Remap(template.CacheMissLog);
            DevLog                           = pathRemapper.Remap(template.DevLog);
            RpcLog                           = pathRemapper.Remap(template.RpcLog);
            PipOutputLog                     = pathRemapper.Remap(template.PipOutputLog);
            FailPipOnFileAccessError         = template.FailPipOnFileAccessError;
            LogMemory                        = template.LogMemory;
            ReplayWarnings                   = template.ReplayWarnings;
            UseCustomPipDescriptionOnConsole = template.UseCustomPipDescriptionOnConsole;
            CacheMissAnalysisOption          = new CacheMissAnalysisOption(
                template.CacheMissAnalysisOption.Mode,
                new List <string>(template.CacheMissAnalysisOption.Keys),
                pathRemapper.Remap(template.CacheMissAnalysisOption.CustomPath));
        }
Пример #34
0
 public ApiClientFactory(ILoginCache loginCache, IProgram program, ILoggingConfiguration config)
 {
     LoginCache    = loginCache;
     productHeader = program.ProductHeader;
     config.Configure();
 }
 private static PathTranslator GetPathTranslator(ILoggingConfiguration conf, PathTable pathTable)
 {
     return(conf.SubstTarget.IsValid && conf.SubstSource.IsValid
         ? new PathTranslator(conf.SubstTarget.ToString(pathTable), conf.SubstSource.ToString(pathTable))
         : null);
 }
Пример #36
0
        public AppLogger(ILoggingConfiguration loggingConfiguration)
        {
            _logglyKey = loggingConfiguration.LogglyKey;

            _logger = new Logger(_logglyKey);
        }