public static void ConfigureLogging()
        {
            var logConfig        = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Console();
            var loggingDirectory = ConfigUtils.ReadSettingFromAppConfigIfPresent("LoggingDirectory");

            if (loggingDirectory != null)
            {
                if (!Path.IsPathRooted(loggingDirectory))
                {
                    loggingDirectory = Path.Combine(Assembly.GetEntryAssembly().Location, loggingDirectory);
                }
                logConfig.WriteTo.File(Path.Combine(loggingDirectory, "SampleA2aService-{Date}.log"),
                                       LogEventLevel.Debug);
            }
            Log.Logger = logConfig.CreateLogger();
        }
        public static void CheckForDebugHook()
        {
#if DEBUG
            var debugBreak = ConfigUtils.ReadSettingFromAppConfigIfPresent("DebugBreak");
            if (bool.TryParse(debugBreak, out var waitForDebugger) && waitForDebugger)
            {
                while (!Debugger.IsAttached)
                {
                    Task.Delay(TimeSpan.FromSeconds(2)).Wait();
                    Log.Debug("Waiting for debugger to attach");
                }
                Debugger.Break();
                Log.Debug("Debugger attached");
            }
#endif
        }
Exemple #3
0
        static void Main()
        {
            ConfigUtils.ConfigureLogging();

            HostFactory.Run(hostConfig =>
            {
                hostConfig.Service <SampleService>(service =>
                {
                    service.ConstructUsing(c => new SampleService());
                    service.WhenStarted(s => s.Start());
                    service.WhenStopped(s => s.Stop());
                });
                hostConfig.UseSerilog();
                hostConfig.StartAutomaticallyDelayed();
                hostConfig.SetDisplayName("SampleA2aService");
                hostConfig.SetServiceName("SampleA2aService");
                hostConfig.SetDescription("Simple application to notify when a password changes.");
            });
        }
Exemple #4
0
        public void Start()
        {
            ConfigUtils.CheckForDebugHook();

            // connect to Safeguard
            _connection = Safeguard.Connect(_safeguardAddress, _safeguardClientCertificateThumbprint,
                                            _safeguardApiVersion, _safeguardIgnoreSsl);
            _a2AContext = Safeguard.A2A.GetContext(_safeguardAddress, _safeguardClientCertificateThumbprint,
                                                   _safeguardApiVersion, _safeguardIgnoreSsl);

            // figure out what API keys to monitor
            GetApiKeysFromA2ARegistrations();
            if (_monitoredPasswords.Count == 0)
            {
                throw new Exception("No API keys found in A2A registrations.  Nothing to do.");
            }
            Log.Information("Found {MonitoredPasswordCount} API keys to monitor for password changes", _monitoredPasswords.Count);

            // start the listeners
            foreach (var monitored in _monitoredPasswords)
            {
                StartListener(monitored);
            }
        }