public PublishLogEvent(string logType, string logMessage) { this.Id = Guid.NewGuid(); this.Timestamp = DateTime.UtcNow; this.LogType = logType; this.LogMessage = logMessage; this.IP = DnsHelper.GetIpAddressAsync().GetAwaiter().GetResult(); }
public async Task BeEmptyWhenNoAddresses() { var hostEntryProvider = Substitute.For <IHostEntryProvider>(); hostEntryProvider.GetHostEntryAsync().Returns(new IPHostEntry()); var address = await DnsHelper.GetIpAddressAsync(hostEntryProvider); Assert.Empty(address); }
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime) { var log = loggerFactory .AddNLog() //.AddConsole() //.AddDebug() .CreateLogger <Startup>(); loggerFactory.ConfigureNLog("NLog.config"); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); app.UseSwagger((httpRequest, swaggerDoc) => { swaggerDoc.Host = httpRequest.Host.Value; }); app.UseSwaggerUi(); // add tenant & health check var localAddress = DnsHelper.GetIpAddressAsync().Result; var uri = new Uri($"http://{localAddress}:{Program.PORT}/"); log.LogInformation("Registering tenant at ${uri}"); var registryInformation = app.AddTenant("values", "1.0.0-pre", uri, tags: new[] { "urlprefix-/values" }); log.LogInformation("Registering additional health check"); //var checkId = app.AddHealthCheck(registryInformation, new Uri(uri, "status"), TimeSpan.FromSeconds(15), "status"); // prepare checkId for options injection //app.ApplicationServices.GetService<IOptions<HealthCheckOptions>>().Value.HealthCheckId = checkId; // register service & health check cleanup applicationLifetime.ApplicationStopping.Register(() => { log.LogInformation("Removing tenant & additional health check"); //app.RemoveHealthCheck(checkId); app.RemoveTenant(registryInformation.Id); _consulConfigCancellationTokenSource.Cancel(); }); }
private async Task <string> GetServiceIdAsync(string serviceName, Uri uri) { var ipAddress = await DnsHelper.GetIpAddressAsync(); return($"{serviceName}_{ipAddress.Replace(".", "_")}_{uri.Port}"); }
private async Task <string> GetServiceIdAsync(string serviceName, Uri uri) { var ipAddress = await DnsHelper.GetIpAddressAsync(s_hostEntryProvider).ConfigureAwait(false); return($"{serviceName}_{ipAddress.Replace(".", "_")}_{uri.Port}"); }
public async Task GetIpv6AddressAsync() { var address = await DnsHelper.GetIpAddressAsync(new DnsHostEntryProvider(), ipv4 : false); Assert.NotEmpty(address); }
public async Task GetIpv4AddressAsync() { var address = await DnsHelper.GetIpAddressAsync(); Assert.NotEmpty(address); }