public MyBasedServiceAHostedService(ILoggerFactory loggerFactory) { this._logger = loggerFactory.CreateLogger <MyBasedServiceAHostedService>(); GrpcEnvironment.SetLogger(new GrpcLogger(_logger)); _server = new Server { Services = { UserInfoService.BindService(new UserInfoServiceImpl()) }, Ports = { new ServerPort("0.0.0.0", 9999, ServerCredentials.Insecure) } }; }
public MyBasedServiceAHostedService(ILoggerFactory loggerFactory, IConfiguration configuration, IConsulClient consulClient, IHostingEnvironment environment) { this._logger = loggerFactory.CreateLogger <MyBasedServiceAHostedService>(); this._configuration = configuration; this._consulClient = consulClient; var port = _configuration.GetValue <int>("AppSettings:Port"); _logger.LogInformation($"{environment.EnvironmentName} Current Port is : {port}"); // global logger for grpc GrpcEnvironment.SetLogger(new GrpcAdapterLogger(loggerFactory)); var address = GetLocalIP(); _logger.LogInformation($"{environment.EnvironmentName} Current IP is : {address}"); registration = new AgentServiceRegistration() { ID = $"MyBasedServiceA-{Guid.NewGuid().ToString("N")}", Name = "MyBasedServiceA", Address = address, Port = port, Check = new AgentServiceCheck { TCP = $"{address}:{port}", DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(5), Interval = TimeSpan.FromSeconds(10), Timeout = TimeSpan.FromSeconds(5) } }; _server = new Server { Ports = { new ServerPort("0.0.0.0", port, ServerCredentials.Insecure) } }; // not production record some things if (!environment.IsProduction()) { _server.Services.Add(UserInfoService.BindService(new UserInfoServiceImpl()).Intercept(new AccessLogInterceptor(loggerFactory))); } else { _server.Services.Add(UserInfoService.BindService(new UserInfoServiceImpl())); } }