internal Task <int> RunAsync(
            string[] args,
            TSettings settings,
            IDirectoryStatic directory,
            ILog log,
            TelemetryConfiguration telemetryConfiguration)
        {
            if (log == null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            // Must receive log object from entry point so that logging is initialized properly.
            log.Debug("Initialized logging.");

            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                log.Fatal("Terminating application due to unhandled exception.", e.ExceptionObject as Exception);
            };
            TaskScheduler.UnobservedTaskException += (s, e) =>
            {
                log.Fatal("Terminating application due to unobserved task exception.", e.Exception);
            };

            // Services have their starting current directory set to the system directory. The current directory must
            // be set to the base directory so the settings file may be found.
            directory.SetCurrentDirectory(AppContext.BaseDirectory);
            // Settings must be loaded before accessing them.
            settings.Reload();
            // Write default settings if settings file does not exist.
            settings.Save(force: true);

            if (string.IsNullOrEmpty(settings.InstrumentationKey) &&
                telemetryConfiguration.InstrumentationKey == "" &&
                !args.Any())
            {
                log.Warn("An Application Insights instrumentation key is not set. Telemetry will not be reported to Application Insights.");
            }
            else
            {
                telemetryConfiguration.InstrumentationKey = settings.InstrumentationKey;
            }

            return(RunAsyncOverride(args, settings));
        }
Esempio n. 2
0
 public RuleAssemblyLoader(IFileStatic file, IDirectoryStatic directory, IAssemblyStatic assembly)
 {
     _file      = file;
     _directory = directory;
     _assembly  = assembly;
 }