public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory LoggerFactory, ILogger<Startup> logger) { LoggerFactory.AddConsole(LogLevel.Information); app.Use(async (context, next) => { var s = ("[Pipeline0] Request to:" + context.Request.Path); logger.LogInformation(s); await next(); }); app.UseStaticFiles(); app.UseErrorPage(); app.UseMvc(); }
public static void DropDatabase(string databaseName, ILogger logger) { try { logger.LogInformation("Trying to drop database '{0}'", databaseName); using (var conn = new SqlConnection(string.Format(CONNECTION_STRING_FORMAT, "master"))) { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = string.Format(@"IF EXISTS (SELECT * FROM sys.databases WHERE name = N'{0}') BEGIN ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [{0}]; END", databaseName); cmd.ExecuteNonQuery(); logger.LogInformation("Successfully dropped database {0}", databaseName); } } catch (Exception exception) { //Ignore if there is failure in cleanup. logger.LogWarning("Error occurred while dropping database {0}. Exception : {1}", databaseName, exception.ToString()); } }
public async Task RunExecutableAsync(FileInfo executableFile, Stream stream, string arguments) { logger?.LogInformation($"Invoking executable {executableFile.FullName} with the following arguments: {arguments}"); using var process = new Process(); process.StartInfo = new ProcessStartInfo { FileName = executableFile.FullName, Arguments = arguments, RedirectStandardOutput = true, }; process.EnableRaisingEvents = true; process.Start(); var output = await process.StandardOutput.ReadToEndAsync(); process.WaitForExit(); using var streamWriter = new StreamWriter(stream); await streamWriter.WriteAsync(output); logger?.LogInformation($"Executable has finished running. Result code: {process.ExitCode}"); if (process.ExitCode != 0) { throw new InvalidOperationException($"Executable failed with exit code: {process.ExitCode}"); } }
private static async Task RanCommand(string[] args, ILogger?log = null, CancellationToken token = default) { if (args == null || args.Length == 0) { log?.LogWarning("Missing command arguments"); return; } log?.LogInformation($"Starting {String.Join(" ", args)}"); var rootCommand = new RootCommand(); rootCommand.AddCommand(BankRunCommand()); rootCommand.AddCommand(DataPushCommand()); rootCommand.AddCommand(EventReceiptingCommand()); rootCommand.AddCommand(YearlyGivingCalculationCommand()); rootCommand.AddCommand(YearlyGivingFullRecalculationCommand()); rootCommand.AddCommand(PerfomanceCalculationCommand()); rootCommand.Handler = CommandHandler.Create((IHelpBuilder help) => help.Write(rootCommand)); var parser = new CommandLineBuilder(rootCommand); await parser .UseHelp() .UseParseErrorReporting() .UseHost(Host.CreateDefaultBuilder, builder => builder.ConfigureHostBuilder(log)) .Build() .InvokeAsync(args); log?.LogInformation($"Existing {args[0]}"); }
public async Task BuildAsync(EntryPointOperation entryPoint, IList <DirectoryInfo> libraryDirectories, IList <DirectoryInfo> includeDirectories) { var sourceDirectory = new DirectoryInfo(SourceDirectoryPath); if (sourceDirectory.Exists) { sourceDirectory.Delete(true); } sourceDirectory.Create(); logger?.LogInformation($"Created source directory at {sourceDirectory.FullName}."); // Create driver. var driverFileNameWithExtension = Path.ChangeExtension(DriverFileName, DriverFileExtension); var driverFile = new FileInfo(Path.Combine(sourceDirectory.FullName, driverFileNameWithExtension)); using (var driverFileStream = driverFile.OpenWrite()) { await driverGenerator.GenerateAsync(entryPoint, driverFileStream); } logger?.LogInformation($"Created driver file at {driverFile.FullName}."); // Create bitcode file. var bitcodeFile = new FileInfo(Path.Combine(sourceDirectory.FullName, BitcodeFileName)); using (var bitcodeFileStream = bitcodeFile.OpenWrite()) { await bitcodeFileStream.WriteAsync(qirBitcode); } logger?.LogInformation($"Created bitcode file at {bitcodeFile.FullName}."); await executableGenerator.GenerateExecutableAsync(ExecutableFile, sourceDirectory, libraryDirectories.Concat(this.LibraryDirectories).ToList(), includeDirectories.Concat(this.HeaderDirectories).ToList(), LinkLibraries); }
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration, ILogger?logger = null) { services // Helpers. .AddSingleton <ITvDbClient, TvDbClient>() .AddSingleton <IMemoryCache, MemoryCache>() .AddSingleton <Compiler>(x => new SqlServerCompiler()) // Repos .AddTransient <IShowRepository, ShowRepository>() .AddTransient <IEpisodeRepository, EpisodeRepository>() // API .AddTransient <IApiSearch, TvDbSearch>() .AddTransient <IEpisodeApiSearch, TvDbSearch>() .AddTransient <IShowApiSearch, TvDbSearch>(); // Add Config. Prioritize ENV over APPSettings. // TVDB Options var tvDbOptions = configuration.GetSection("TvDb").Get <TvDbOptions>(); tvDbOptions.ApiKey = EnviromentHelper.FindGlobalEnviromentVariable("TVDB_APIKEY") ?? (!string.IsNullOrWhiteSpace(tvDbOptions.ApiKey) ? tvDbOptions.ApiKey : throw new ApplicationException("TVDB_APIKEY NOT SPECIFIED. USE AN ENVIROMENT VAR.")); // MediaInfo Options var mediaInfoConnString = GetMediaInfoDbConnection(configuration); logger?.LogInformation($"[SETTINGS]: TVDB_APIKEY - {tvDbOptions.ApiKey}"); logger?.LogInformation($"[SETTINGS]: MEDIAINFO_DB - {mediaInfoConnString}"); return(services .AddSingleton <IDbConnectionFactory>(_ => new SqlConnectionFactory(mediaInfoConnString)) .AddSingleton(tvDbOptions)); }
public ChangeCalculatorResult CalculateChanges(IEnumerable <ITypeDefinition> oldTypes, IEnumerable <ITypeDefinition> newTypes, ComparerOptions options) { oldTypes = oldTypes ?? throw new ArgumentNullException(nameof(oldTypes)); newTypes = newTypes ?? throw new ArgumentNullException(nameof(newTypes)); var result = new ChangeCalculatorResult(); var changes = _matchProcessor.CalculateChanges(oldTypes, newTypes, options); foreach (var change in changes) { if (change.ChangeType == SemVerChangeType.None) { continue; } _logger?.LogInformation($@"{change.ChangeType}: {change.Message}"); result.Add(change); } var changeType = result.ChangeType.ToString().ToLower(CultureInfo.CurrentCulture); _logger?.LogInformation("Calculated overall result as a {0} change.", changeType); return(result); }
/// <inheritdoc/> protected override async Task OnOpeningAsync(CancellationToken token = default) { if (RemoteEndpoint.Server == null) { // If specific endpoint is not provided, use discovery to select endpoint with highest // security level. var endpointUrl = RemoteEndpoint.EndpointUrl; var securityPolicyUri = RemoteEndpoint.SecurityPolicyUri; try { _logger?.LogInformation($"Discovering endpoints of '{endpointUrl}'."); var getEndpointsRequest = new GetEndpointsRequest { EndpointUrl = endpointUrl, ProfileUris = new[] { TransportProfileUris.UaTcpTransport } }; var getEndpointsResponse = await UaTcpDiscoveryService.GetEndpointsAsync(getEndpointsRequest, _loggerFactory).ConfigureAwait(false); if (getEndpointsResponse.Endpoints == null || getEndpointsResponse.Endpoints.Length == 0) { throw new InvalidOperationException($"'{endpointUrl}' returned no endpoints."); } var selectedEndpoint = getEndpointsResponse.Endpoints .OfType <EndpointDescription>() .Where(e => string.IsNullOrEmpty(securityPolicyUri) || e.SecurityPolicyUri == securityPolicyUri) .OrderBy(e => e.SecurityLevel) .LastOrDefault(); if (selectedEndpoint is null) { throw new InvalidOperationException($"'{endpointUrl}' returned no endpoint for the requested security policy '{securityPolicyUri}'."); } RemoteEndpoint.Server = selectedEndpoint.Server; RemoteEndpoint.ServerCertificate = selectedEndpoint.ServerCertificate; RemoteEndpoint.SecurityMode = selectedEndpoint.SecurityMode; RemoteEndpoint.SecurityPolicyUri = selectedEndpoint.SecurityPolicyUri; RemoteEndpoint.UserIdentityTokens = selectedEndpoint.UserIdentityTokens; RemoteEndpoint.TransportProfileUri = selectedEndpoint.TransportProfileUri; RemoteEndpoint.SecurityLevel = selectedEndpoint.SecurityLevel; _logger?.LogTrace($"Success discovering endpoints of '{endpointUrl}'."); } catch (Exception ex) { _logger?.LogError($"Error discovering endpoints of '{endpointUrl}'. {ex.Message}"); throw; } } // Ask for user identity. May show dialog. if (UserIdentityProvider != null) { UserIdentity = await UserIdentityProvider(RemoteEndpoint); } await base.OnOpeningAsync(token); }
private Task InternalExecuteScriptAsync(NpgsqlConnection connection, string script, CancellationToken token = default) { var command = connection.CreateCommand(); command.CommandText = script; _sqLogger?.LogInformation(script); return(command.ExecuteNonQueryAsync(token)); }
/// <summary> /// Stops all listeners. /// </summary> public void Stop() { foreach (var listener in _listeners) { listener.Stop(); } _listeners.Clear(); _acceptors.Clear(); Port = 0; _logger?.LogInformation("Listener stopped"); }
public void Enter(ActionExecutingContext context) { var requestId = GetRequestId(context); var requestInfo = GetRequestInfo(context); var stats = GetActionStats(context); _logger?.LogInformation( $"Enter(Id:{requestId}, Action:{stats.ActionName}, Request:{requestInfo})"); stats.Enter(); var requestStartTick = Ticks; _requestInfo.TryAdd(requestId, requestStartTick); }
public async Task GenerateExecutableAsync(FileInfo executableFile, DirectoryInfo sourceDirectory, IList <DirectoryInfo> libraryDirectories, IList <DirectoryInfo> includeDirectories, IList <string> linkLibraries) { // Wrap in a Task.Run because FileInfo methods are not asynchronous. await Task.Run(async() => { var binDirectory = executableFile.Directory; logger?.LogInformation($"Creating binary directory at {binDirectory.FullName}."); executableFile.Directory.Create(); // Copy all library contents to bin. logger?.LogInformation("Copying library directories into the executable's folder."); if (!sourceDirectory.Exists) { logger?.LogWarning($"Cannot find source directory: {sourceDirectory.FullName}"); } var libDirs = new List <string>(); foreach (var dir in libraryDirectories) { if (!dir.Exists) { logger?.LogWarning($"Cannot find given directory: {dir.FullName}"); } else { CopyDirectoryFilesIfNotExist(dir, binDirectory); libDirs.Add(dir.FullName); } } var includeDirs = new List <string>(); foreach (var dir in includeDirectories) { if (!dir.Exists) { logger?.LogWarning($"Could not find given directory: {dir.FullName}"); } else { includeDirs.Add(dir.FullName); } } var inputFiles = sourceDirectory.GetFiles().Select(fileInfo => fileInfo.FullName).ToArray(); await clangClient.CreateExecutableAsync(inputFiles, linkLibraries.ToArray(), libDirs.ToArray(), includeDirs.ToArray(), executableFile.FullName); }); }
protected internal StepMotor(SerialPort port, Address?address, ILogger?logger, TimeSpan defaultTimeOut = default) { address ??= Address.DefaultStart; TimeOut = defaultTimeOut == default ? TimeSpan.FromMilliseconds(300) : defaultTimeOut; Address = address.Value; Port = port; Logger = logger; // Event listeners Port.NewLine = "\r"; if (!Port.IsOpen) { //Port.ReceivedBytesThreshold = ResponseSizeInBytes; // Creates port Port.BaudRate = 9600; Port.Parity = Parity.None; Port.DataBits = 8; Port.StopBits = StopBits.One; Port.Open(); } Port.DiscardInBuffer(); Port.DiscardOutBuffer(); Port.ErrorReceived += Port_ErrorReceived; Id = new MotorId(Port.PortName, Address); Logger?.LogInformation("{StepMotor}: Created", Id); }
public async Task <int> GetPositionAsync(MotorBank motorOrBank = default) { var reply = await SendCommandAsync( Command.GetAxisParameter, 0, CommandParam.AxisParameter.ActualPosition, motorOrBank); if (reply.IsSuccess) { Logger?.LogInformation("{StepMotor}: Position = {Position}", Id, reply.ReturnValue); return(reply.ReturnValue); } throw LogThenFail(); }
public StopController(IWorldRepository repo, ILogger<StopController> logger, CoordService coordService) { this.repo = repo; this.logger = logger; logger.LogInformation("Inside StopController ctor"); this.coordService = coordService; }
public static IServiceCollection AddDomain(this IServiceCollection services, IConfiguration configuration, ILogger?logger = null) { services .AddTransient <EpisodeSearch>() .AddTransient <ShowSearch>() .AddTransient <ShowStorage>(); // Add Config Options. var storagePaths = Array.Empty <string>(); if (EnviromentHelper.TryGetGlobalEnviromentVariable("MEDIAINFO_STORAGE", out string envValue)) { storagePaths = JsonSerializer.Deserialize <string[]>(envValue); } else { storagePaths = configuration.GetSection("Storage").Get <string[]>(); } if (storagePaths.Any(path => !Directory.Exists(path))) { throw new ApplicationException($"STORAGEPATH DOES NOT EXIST: {string.Join(", ", storagePaths.Where(path => !Directory.Exists(path)))}"); } logger?.LogInformation($"[SETTINGS]: Storage - {string.Join(", ", storagePaths)}"); return(services .AddSingleton(new MediaInfoConfiguration { StoragePaths = storagePaths })); }
public async Task Cleanup(MongoContainer container, CancellationToken token = new CancellationToken()) { if (container == null) { throw new ArgumentNullException(nameof(container)); } var client = new MongoClient(container.GetConnectionString()); var databaseNames = (await client.ListDatabasesAsync(token)).ToList().Select(x => x["name"].AsString) .ToList(); try { foreach (var databaseName in databaseNames) { if (databaseName != "admin" && databaseName != "local") { await client.DropDatabaseAsync(databaseName, token); } } } catch (Exception e) { _logger?.LogInformation($"MongoDB cleanup issue: {e.Message}"); } }
public BundleService(IApplicationEnvironment appEnvironment, ILogger<BundleService> logger) { _appEnvironment = appEnvironment; _logger = logger; _logger.LogDebug("Application base path: \"{0}\"", _appEnvironment.ApplicationBasePath); _logger.LogInformation("BundleService created"); }
/// <summary> /// Downloads an image at the provided URL and converts it to a valid Data Uri scheme (https://en.wikipedia.org/wiki/Data_URI_scheme) /// </summary> /// <param name="url">The url where the image is located.</param> /// <param name="logger">A logger.</param> /// <param name="fallbackFileInfo">A FileInfo to retrieve the local fallback image.</param> /// <param name="fallbackMediaType">The media type of the fallback image.</param> /// <param name="messageHandler">An optional message handler.</param> /// <returns>A string that contains the data uri of the downloaded image, or a default image on any error.</returns> public static async Task<string> DownloadImageAndConvertToDataUri(this string url, ILogger logger, IFileInfo fallbackFileInfo, string fallbackMediaType = "image/png", HttpMessageHandler messageHandler = null) { // exclude completely invalid URLs if (!string.IsNullOrWhiteSpace(url)) { try { // set a timeout to 10 seconds to avoid waiting on that forever using (var client = new HttpClient(messageHandler) { Timeout = TimeSpan.FromSeconds(10) }) { var response = await client.GetAsync(url); response.EnsureSuccessStatusCode(); // set the media type and default to JPG if it wasn't provided string mediaType = response.Content.Headers.ContentType?.MediaType; mediaType = string.IsNullOrWhiteSpace(mediaType) ? "image/jpeg" : mediaType; // return the data URI according to the standard return (await response.Content.ReadAsByteArrayAsync()).ToDataUri(mediaType); } } catch (Exception ex) { logger.LogInformation(0, ex, "Error while downloading resource"); } } // any error or invalid URLs just return the default data uri return await fallbackFileInfo.ToDataUri(fallbackMediaType); }
public void Configure(IApplicationBuilder app, ILoggerFactory LoggerFactory, ILogger<Startup> logger) { LoggerFactory.AddConsole(LogLevel.Information); app.Use(async (context, next) => { var s = ("[Pipeline] Request to:" + context.Request.Path); logger.LogInformation(s); Debug.WriteLine(s); await next(); }); //app.Use(async (context, next) => //{ // var s = ("Headers:\n" + JsonConvert.SerializeObject(context.Request.Headers, Formatting.Indented)); // logger.LogInformation(s); // Debug.WriteLine(s); // s = ("Body:\n" + JsonConvert.SerializeObject(context.Request.Form, Formatting.Indented)); // logger.LogInformation(s); // Debug.WriteLine(s); // await next(); //}); app.UseStaticFiles(); app.UseErrorPage(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}", defaults: new { controller = "Page", action = "Index" }); }); }
public static void Main(string[] args) { var configBuilder = new ConfigurationBuilder().AddCommandLine(args); Configuration = configBuilder.Build(); string configFile = Configuration["config"]; if (configFile != null) { configBuilder.AddJsonFile(configFile, optional: false); Configuration = configBuilder.Build(); } ConfigurationBinder.Bind(Configuration.GetSection("startup"), _startupOptions); ConfigurationBinder.Bind(Configuration.GetSection("security"), _securityOptions); _loggerFactory .AddDebug() .AddConsole(LogLevel.Trace) .AddProvider(new FileLoggerProvider(_startupOptions.Name)); _logger = _loggerFactory.CreateLogger<Program>(); if (_startupOptions.Name != null) { _logger.LogInformation(Resources.Info_BrokerName, _startupOptions.Name); } var tlsConfig = new TlsConfiguration(_logger, _securityOptions); var httpsOptions = tlsConfig.GetHttpsOptions(Configuration); Uri uri = GetServerUri(Configuration); try { CreateWebHost(httpsOptions).Run(); } catch(AggregateException ex) when (ex.IsPortInUseException()) { _logger.LogError(0, ex.InnerException, Resources.Error_ConfiguredPortNotAvailable, uri?.Port); } }
public static void SetInMemoryStoreForIIS(DeploymentParameters deploymentParameters, ILogger logger) { if (deploymentParameters.ServerType == ServerType.IIS || deploymentParameters.ServerType == ServerType.IISNativeModule) { // Can't use localdb with IIS. Setting an override to use InMemoryStore. logger.LogInformation("Creating configoverride.json file to override default config."); string overrideConfig; if (deploymentParameters.PublishWithNoSource) { var compileRoot = Path.GetFullPath( Path.Combine( deploymentParameters.ApplicationPath, "..", "approot", "packages", "MusicStore")); // We don't know the exact version number with which sources are built. overrideConfig = Path.Combine(Directory.GetDirectories(compileRoot).First(), "root", "configoverride.json"); } else { overrideConfig = Path.GetFullPath( Path.Combine( deploymentParameters.ApplicationPath, "..", "approot", "src", "MusicStore", "configoverride.json")); } File.WriteAllText(overrideConfig, "{\"UseInMemoryDatabase\": \"true\"}"); } }
public async Task CreateExecutableAsync(string[] inputFiles, string[] linkedLibraries, string[] libraryPaths, string[] includePaths, string outputPath) { var inputsArg = string.Join(' ', inputFiles); // string.Join does not automatically prepend the delimiter, so it is included again in the string here. var linkedLibrariesArg = $"{LinkFlag} {string.Join(LinkFlag, linkedLibraries)}"; var libraryPathsArg = $"{LibraryPathFlag} {string.Join(LibraryPathFlag, libraryPaths)}"; var includePathsArg = $"{IncludePathFlag} {string.Join(IncludePathFlag, includePaths)}"; var arguments = $"{inputsArg} {includePathsArg} {libraryPathsArg} {linkedLibrariesArg} -o {outputPath} -std=c++17 -v"; logger?.LogInformation($"Invoking clang with the following arguments: {arguments}"); var taskCompletionSource = new TaskCompletionSource <bool>(); using var process = new Process(); AddPathsToEnvironmentVariable("DYLD_LIBRARY_PATH", libraryPaths); AddPathsToEnvironmentVariable("LD_LIBRARY_PATH", libraryPaths); process.StartInfo = new ProcessStartInfo { FileName = "clang++", Arguments = arguments, }; process.EnableRaisingEvents = true; process.Exited += (sender, args) => { taskCompletionSource.SetResult(true); }; process.Start(); await taskCompletionSource.Task; }
public Candidate(ServerIdentifier serverIdentifier, IElectionTimer electionTimer, IObserver<RequestVoteMessage> requestVote, IObservable<RequestVoteResultMessage> voteReply, IVotingSystem votingSystem, IElection election, ILogReplication logReplication, Nodes nodes, ILoggerFactory loggerFactory, RaftOptions options) { isDispose = false; _electionTimer = electionTimer; _requestVote = requestVote; _voteReply = voteReply; _votingSystem = votingSystem; _serverIdentifier = serverIdentifier; _election = election; _options = options; _logger = loggerFactory.CreateLogger(nameof(Candidate) + " " + serverIdentifier); _election.CurrentTerm++; _election.VotedFor = _serverIdentifier.Id; _logReplication = logReplication; _nodes = nodes; if (_options.UseLogging) _logger.LogInformation($"{nameof(ServerStateType.Candidate)}"); RequestElection(); }
// Here we've automatically gotten an ILogger injected by DNX and our Autofac container. Weee! :) public HelloWorldModule(ILogger<HelloWorldModule> logger) { Get["/"] = _ => { logger.LogInformation("Hello World!"); return "Hello World!"; }; }
public ElasticSearchDataHelper(IConfigurationElasticClientSettings elasticClientSettings, ILoggerFactory loggerFactory) { log = loggerFactory.CreateLogger<ElasticSearchDataHelper>(); log.LogWarning("Inside ElasticSearchDataHelper"); itemCount = elasticClientSettings.DefaultItemCount; client = elasticClientSettings.Client; log.LogInformation(DateTime.Now.ToLongTimeString() + "connstring=" + elasticClientSettings.ConnectionString); }
public Timeline(ISerializer serializer, ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger(typeof(Timeline).Name); _logger.LogInformation("Timeline"); _serializer = serializer; var connectionString = $"DefaultEndpointsProtocol=https;AccountName={account};AccountKey={primaryAccessKey}"; _logger.LogInformation("Create storage account"); var storageAccount = CloudStorageAccount.Parse(connectionString); _logger.LogInformation("Create table client"); var tableClient = storageAccount.CreateCloudTableClient(); _logger.LogInformation("Create table if not exists"); _table = tableClient.GetTableReference("Timeline"); _table.CreateIfNotExists(); _logger.LogInformation("Created"); }
/// <summary> /// Starts the hosted service and initializes the consumer or producer by either setting up the consumption of /// messages or by starting the producer's message queueing functionality. /// /// For details on the default implementations of consumers and producers, see <see cref="RabbitMqConsumer{T}"/> /// and <see cref="RabbitMqProducer{T}"/>. /// </summary> /// <param name="cancellationToken"/> /// <returns/> public virtual Task StartAsync(CancellationToken cancellationToken) { Debug.Assert( _isProperlyInitialized, $"This {nameof(RabbitMqService<T>)} instance should have been created through a call to " + $"{nameof(RabbitMqService<T>)}.{nameof(Create)}."); _logger?.LogInformation($"RabbitMqService {_rmqConfig.Id} is starting."); if (Bus.IsConnected) { _logger?.LogDebug($"Connected to RabbitMQ with configuration {_rmqConfig.Id}."); } Bus.Connected += (sender, args) => _logger?.LogDebug($"Connected to RabbitMQ with configuration {_rmqConfig.Id}."); Bus.Disconnected += (sender, args) => _logger?.LogDebug($"Disconnected from RabbitMQ with configuration {_rmqConfig.Id}."); // run the setup callbacks on connection if (Bus.IsConnected) { _onConnected.ForEach(callback => HandleCallbackError(callback)(Bus, _rmqConfig, cancellationToken, _logger)); } _onConnected.ForEach(callback => Bus.Connected += (sender, args) => HandleCallbackError(callback)(Bus, _rmqConfig, cancellationToken, _logger)); if (_isConsumer) { InitializeConsumer(cancellationToken); } else { InitializeProducer(cancellationToken); } return(Task.CompletedTask); }
/// <summary> /// Constructor /// </summary> /// <param name="manager">The chat repository manager</param> public ChatHub(IChatManager<string, ChatLeUser, Conversation, Attendee, Message, NotificationConnection> manager, ILoggerFactory loggerFactory) : base() { if (manager == null) throw new ArgumentNullException("manager"); if (loggerFactory == null) throw new ArgumentNullException("loggerFactory"); Logger = loggerFactory.CreateLogger<ChatHub>(); Logger.LogInformation("constructor"); Manager = manager; }
private static void Report(ILogger?logger, string dbSetName, int recordsCount, int recordsWritten) { if (recordsCount == recordsWritten) { logger?.LogInformation($"seeded {dbSetName}: {recordsWritten}/{recordsCount} records."); } else { logger?.LogWarning($"seeded {dbSetName}: {recordsWritten}/{recordsCount} records."); } }
public Startup(IApplicationEnvironment env, ILoggerFactory loggerFactory) { _configuration = new ConfigurationBuilder() .AddJsonFile(env.ApplicationBasePath) .AddEnvironmentVariables() .Build(); var loglevel = _configuration.Get("DefaultLogLevel"); loggerFactory.AddConsole((LogLevel)Enum.Parse(typeof(LogLevel), loglevel)); _logger = loggerFactory.CreateLogger<Startup>(); _logger.LogInformation("fex server startin..."); }
public static async Task AssertIsTrueRetryAsync(Func <Task <bool> > assert, string message, ILogger?logger = null) { const int Retries = 10; logger?.LogInformation("Start: " + message); for (var i = 0; i < Retries; i++) { if (i > 0) { await Task.Delay((i + 1) *(i + 1) * 10); } if (await assert()) { logger?.LogInformation("End: " + message); return; } } throw new Exception($"Assert failed after {Retries} retries: {message}"); }
protected async Task RunBatchesAsync(ICollection <ScriptMigrationBatch> batches, CancellationToken token = default) { var needLogBatches = batches.Count > 1; foreach (var batch in batches.OrderBy(b => b.OrderIndex)) { if (needLogBatches) { MigrationLogger?.LogInformation( $"Executing migration's batch #{batch.OrderIndex} \"{batch.Name ?? "No name provided"}\""); } await DbProvider.ExecuteScriptAsync(batch.Script, token); } }
public async Task <bool> Wait(MongoContainer?container, CancellationToken cancellationToken) { if (container == null) { throw new ArgumentNullException(nameof(container)); } try { _logger?.LogInformation($"MongoDB: checking container state..."); await new MongoClient(container.GetConnectionString()).ListDatabasesAsync(cancellationToken); _logger?.LogInformation($"MongoDB: container is Up!"); return(true); } catch (Exception e) { _logger?.LogError($"MongoDB: check failed with exception {e.Message}"); return(false); } }
public void Run(string fileName) { if (_device is null) { throw new ArgumentNullException("Сканер не найден"); } if (_saver is null) { throw new ArgumentNullException("Обработчик не найден"); } _logger?.LogInformation("Сохранение в формат в {0}", _saver.GetType()); _saver.ScanAndSave(_device, fileName); }
private void Init(IAdminPortTcpClient adminPortTcpClient) { adminPortTcpClient.MessageReceived += AdminPortTcpClient_MessageReceived; adminPortTcpClient.Errored += AdminPortTcpClient_Errored; Context.StateChanged += Context_StateChanged; this.StateRunners[AdminConnectionState.Idle] = new AdminPortIdleState(); this.StateRunners[AdminConnectionState.Connecting] = new AdminPortConnectingState(); this.StateRunners[AdminConnectionState.Disconnecting] = new AdminPortDisconnectingState(); this.StateRunners[AdminConnectionState.Connected] = new AdminPortConnectedState(); this.StateRunners[AdminConnectionState.Errored] = new AdminPortErroredState(); this.StateRunners[AdminConnectionState.ErroredOut] = new AdminPortErroredOutState(); logger?.LogInformation($"{ServerInfo} Admin Port Client Initialized."); }
public GutekScriptTagHelper(ILogger<GutekScriptTagHelper> logger , IHostingEnvironment env , IMemoryCache cache , IHtmlEncoder htmlEncoder , IJavaScriptStringEncoder javaScriptEncoder , IUrlHelper urlHelper) : base(urlHelper, htmlEncoder) { Logger = logger; HostingEnvironment = env; Cache = cache; JavaScriptEncoder = javaScriptEncoder; logger.LogInformation("Initializing Gutek Script Tag Helper"); }
public async Task StopAsync(CancellationToken cancellationToken) { if (_refreshTask is null) { return; } _cts.Cancel(); await _refreshTask.ConfigureAwait(false); _refreshTask = null; _logger?.LogInformation("Refreshing loop cancelled"); await _host.WaitForShutdownAsync().ConfigureAwait(false); }
public DefaultChatBehaviour(MtaServer server, ChatBox chatBox, ILogger?logger) { server.PlayerJoined += (player) => { player.CommandEntered += (sender, arguments) => { if (arguments.Command == "say") { string message = $"{player.Name}: {string.Join(' ', arguments.Arguments)}"; chatBox.Output(message, Color.White, true, ChatEchoType.Player, player); logger?.LogInformation("{message}", message); } }; }; }
public int Run() { _logger?.LogInformation("Running application in RUN mode."); using var packer = _serviceProvider.GetService <IPacker>(); try { packer.Pack(); } catch (Exception e) { _logger?.LogError($"Unable to pack a MEG file: {e.Message}", e); return(1); } return(0); }
/// <summary> /// Add or updates arbitrary storage configuration for a tenant. /// </summary> /// <param name="tenantStore">The tenant store.</param> /// <param name="tenant">The tenant to enroll.</param> /// <param name="configurationItems">Configuration to add.</param> /// <param name="logger">Optional logger.</param> /// <returns>A task which completes when the configuration has been added.</returns> public static async Task AddOrUpdateStorageConfigurationAsync(this ITenantStore tenantStore, ITenant tenant, ConfigurationItem[] configurationItems, ILogger?logger = null) { if (tenant == null) { throw new ArgumentNullException(nameof(tenant)); } tenant.EnsureTenantIsOfType(MarainTenantType.Client); if (configurationItems == null) { throw new ArgumentNullException(nameof(configurationItems)); } logger?.LogDebug( "Add configuration for tenant '{tenantName}' with Id '{tenantId}'", tenant.Name, tenant.Id); configurationItems.ValidateAndThrow(); IEnumerable <KeyValuePair <string, object> > propertiesToAddToTenant = PropertyBagValues.Empty; foreach (ConfigurationItem configurationItem in configurationItems) { logger?.LogDebug( "Adding configuration entry to tenant '{tenantName}' with Id '{tenantId}'", tenant.Name, tenant.Id); propertiesToAddToTenant = configurationItem.AddConfiguration(propertiesToAddToTenant); } logger?.LogDebug( "Updating tenant '{tenantName}' with Id '{tenantId}'", tenant.Name, tenant.Id); tenant = await tenantStore.UpdateTenantAsync( tenant.Id, propertiesToSetOrAdd : propertiesToAddToTenant) .ConfigureAwait(false); logger?.LogInformation( "Successfully added configuration to tenant '{tenantName}' with Id '{tenantId}'", tenant.Name, tenant.Id); }
public Follower(ILoggerFactory loggerFactory, Nodes nodes, RaftOptions options, ServerIdentifier serverIdentifier) { isDispose = false; _options = options; _serverIdentifier = serverIdentifier; nodes.Clear(); _logger = loggerFactory.CreateLogger(nameof(Follower) + " " + serverIdentifier); if (_options.UseLogging) _logger.LogInformation($"{nameof(ServerStateType.Follower)}"); }
public DefaultChatBehaviour(MtaServer server, ILogger?logger) { server.PlayerJoined += (player) => { player.OnCommand += (command, arguments) => { if (command == "say") { string message = $"{player.Name}: {string.Join(' ', arguments)}"; var packet = new ChatEchoPacket(player.Id, message, Color.White); server.BroadcastPacket(packet); logger?.LogInformation(message); } }; }; }
private IScope?LogAndTrace(string?callerMemberName, string?callerFilePath, HttpMethod httpMethod, Uri uri, string?body) { var scope = LogAndTrace(callerMemberName, callerFilePath); scope?.Span.SetTag(nameof(httpMethod), httpMethod.Method); scope?.Span.SetTag(nameof(uri), uri.OriginalString); scope?.Span.SetTag(nameof(body), body); _logger?.LogInformation( new Dictionary <string, object?>(3) { [nameof(httpMethod)] = httpMethod.Method, [nameof(uri)] = uri.OriginalString, [nameof(body)] = body?.Truncate(), }.ToKeyValuePairString()); return(scope); }
public async Task StartAsync(CancellationToken cancellationToken) { if (_measure != null) { _cts = new CancellationTokenSource(); _measureTask = Task.Run(() => MeasureGap(_cts.Token), _cts.Token); } var checkpoint = await _checkpointStore.GetLastCheckpoint(SubscriptionId, cancellationToken); _lastProcessed = new EventPosition(checkpoint.Position, DateTime.Now); Subscription = await Subscribe(checkpoint, cancellationToken); IsRunning = true; _log?.LogInformation("Started subscription {Subscription}", SubscriptionId); }
public DefaultChatBehaviour(IElementRepository elementRepository, ILogger?logger) { Player.OnJoin += (player) => { player.OnCommand += (command, arguments) => { if (command == "say") { string message = $"{player.Name}: {string.Join(' ', arguments)}"; var packet = new ChatEchoPacket(player.Id, message, Color.White); foreach (var _player in elementRepository.GetByType <Player>(ElementType.Player)) { _player.Client.SendPacket(packet); logger?.LogInformation(message); } } }; }; }
public Program(IApplicationEnvironment appEnv) { _logger = new LoggerFactory().AddConsole().CreateLogger("gutek-cmd"); _logger.LogInformation("Runtime: {0}", appEnv.RuntimeFramework.FullName); _appEnv = appEnv; }
private static void LogStartup(ILogger logger, IApplicationEnvironment environment) { logger.LogInformation($"Starting Openchain v{environment.ApplicationVersion} ({environment.RuntimeFramework.FullName})"); logger.LogInformation(" "); }
public TimelineHub(ITimeline timeline, ILoggerFactory loggerFactory ) { _logger = loggerFactory.CreateLogger(typeof(TimelineHub).Name); _logger.LogInformation("Hub created"); _timeline = timeline; }
public void Configuration(IAppBuilder app, IConfiguration configuration, Directory directory, ILoader loader) { // Configure Logging.ApplicationInsights.Initialize(configuration.Get("serilog:ApplicationInsightsInstrumentationKey")); // Create telemetry sink _searchTelemetryClient = new SearchTelemetryClient(); // Create an ILoggerFactory var loggerConfiguration = LoggingSetup.CreateDefaultLoggerConfiguration(withConsoleLogger: false) .Enrich.With<HttpRequestIdEnricher>() .Enrich.With<HttpRequestTraceIdEnricher>() .Enrich.With<HttpRequestTypeEnricher>() .Enrich.With<HttpRequestUrlReferrerEnricher>() .Enrich.With<HttpRequestUserAgentEnricher>() .Enrich.With<HttpRequestRawUrlEnricher>(); // Customize Serilog web logging - https://github.com/serilog-web/classic ApplicationLifecycleModule.RequestLoggingLevel = LogEventLevel.Warning; ApplicationLifecycleModule.LogPostedFormData = LogPostedFormDataOption.OnlyOnError; var loggerFactory = LoggingSetup.CreateLoggerFactory(loggerConfiguration); // Create a logger that is scoped to this class (only) _logger = loggerFactory.CreateLogger<Startup>(); _logger.LogInformation(LogMessages.AppStartup); // Correlate requests app.Use(typeof(CorrelationIdMiddleware)); // Add Application Insights app.Use(typeof(RequestTrackingMiddleware)); // Enable HSTS app.Use(async (context, next) => { context.Response.Headers.Add("Strict-Transport-Security", new string[] { "max-age=31536000; includeSubDomains" }); await next.Invoke(); }); // Enable CORS var corsPolicy = new CorsPolicy { Methods = { "GET", "HEAD", "OPTIONS" }, Headers = { "Content-Type", "If-Match", "If-Modified-Since", "If-None-Match", "If-Unmodified-Since", "Accept-Encoding" }, ExposedHeaders = { "Content-Type", "Content-Length", "Last-Modified", "Transfer-Encoding", "ETag", "Date", "Vary", "Server", "X-Hit", "X-CorrelationId" }, AllowAnyOrigin = true, PreflightMaxAge = 3600 }; app.UseCors(new CorsOptions { PolicyProvider = new CorsPolicyProvider { PolicyResolver = context => Task.FromResult(corsPolicy) } }); // Search test console app.Use(typeof(SearchConsoleMiddleware)); app.UseStaticFiles(new StaticFileOptions(new SharedOptions { RequestPath = new PathString("/console"), FileSystem = new EmbeddedResourceFileSystem(typeof(Startup).Assembly, "NuGet.Services.BasicSearch.Console") })); // Start the service running - the Lucene index needs to be reopened regularly on a background thread var searchIndexRefresh = configuration.Get("Search.IndexRefresh") ?? "300"; int seconds; if (!int.TryParse(searchIndexRefresh, out seconds)) { seconds = 120; } _logger.LogInformation(LogMessages.SearchIndexRefreshConfiguration, seconds); if (InitializeSearcherManager(configuration, directory, loader, loggerFactory)) { var intervalInMs = seconds * 1000; _gate = 0; _indexReloadTimer = new Timer(ReopenCallback, 0, intervalInMs, intervalInMs); } _responseWriter = new ResponseWriter(); app.Run(InvokeAsync); }
public static ProjectFileInfo Create(MSBuildOptions options, ILogger logger, string solutionDirectory, string projectFilePath, ICollection<MSBuildDiagnosticsMessage> diagnostics) { var projectFileInfo = new ProjectFileInfo(); projectFileInfo.ProjectFilePath = projectFilePath; #if DNX451 if (!PlatformHelper.IsMono) { var properties = new Dictionary<string, string> { { "DesignTimeBuild", "true" }, { "BuildProjectReferences", "false" }, { "_ResolveReferenceDependencies", "true" }, { "SolutionDir", solutionDirectory + Path.DirectorySeparatorChar } }; if (!string.IsNullOrWhiteSpace(options.VisualStudioVersion)) { properties.Add("VisualStudioVersion", options.VisualStudioVersion); } var collection = new ProjectCollection(properties); logger.LogInformation("Using toolset {0} for {1}", options.ToolsVersion ?? collection.DefaultToolsVersion, projectFilePath); var project = string.IsNullOrEmpty(options.ToolsVersion) ? collection.LoadProject(projectFilePath) : collection.LoadProject(projectFilePath, options.ToolsVersion); var projectInstance = project.CreateProjectInstance(); var buildResult = projectInstance.Build("ResolveReferences", new Microsoft.Build.Framework.ILogger[] { new MSBuildLogForwarder(logger, diagnostics) }); if (!buildResult) { return null; } projectFileInfo.AssemblyName = projectInstance.GetPropertyValue("AssemblyName"); projectFileInfo.Name = projectInstance.GetPropertyValue("ProjectName"); projectFileInfo.TargetFramework = new FrameworkName(projectInstance.GetPropertyValue("TargetFrameworkMoniker")); projectFileInfo.SpecifiedLanguageVersion = ToLanguageVersion(projectInstance.GetPropertyValue("LangVersion")); projectFileInfo.ProjectId = new Guid(projectInstance.GetPropertyValue("ProjectGuid").TrimStart('{').TrimEnd('}')); projectFileInfo.TargetPath = projectInstance.GetPropertyValue("TargetPath"); var outputType = projectInstance.GetPropertyValue("OutputType"); switch(outputType) { case "Library": projectFileInfo.OutputKind = OutputKind.DynamicallyLinkedLibrary; break; case "WinExe": projectFileInfo.OutputKind = OutputKind.WindowsApplication; break; default: case "Exe": projectFileInfo.OutputKind = OutputKind.ConsoleApplication; break; } projectFileInfo.SourceFiles = projectInstance.GetItems("Compile") .Select(p => p.GetMetadataValue("FullPath")) .ToList(); projectFileInfo.References = projectInstance.GetItems("ReferencePath") .Where(p => !string.Equals("ProjectReference", p.GetMetadataValue("ReferenceSourceTarget"), StringComparison.OrdinalIgnoreCase)) .Select(p => p.GetMetadataValue("FullPath")) .ToList(); projectFileInfo.ProjectReferences = projectInstance.GetItems("ProjectReference") .Select(p => p.GetMetadataValue("FullPath")) .ToList(); projectFileInfo.Analyzers = projectInstance.GetItems("Analyzer") .Select(p => p.GetMetadataValue("FullPath")) .ToList(); var allowUnsafe = projectInstance.GetPropertyValue("AllowUnsafeBlocks"); if (!string.IsNullOrWhiteSpace(allowUnsafe)) { projectFileInfo.AllowUnsafe = Convert.ToBoolean(allowUnsafe); } var defineConstants = projectInstance.GetPropertyValue("DefineConstants"); if (!string.IsNullOrWhiteSpace(defineConstants)) { projectFileInfo.DefineConstants = defineConstants.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); } } else { // On mono we need to use this API since the ProjectCollection // isn't fully implemented #pragma warning disable CS0618 var engine = Engine.GlobalEngine; engine.DefaultToolsVersion = "4.0"; #pragma warning restore CS0618 // engine.RegisterLogger(new ConsoleLogger()); engine.RegisterLogger(new MSBuildLogForwarder(logger, diagnostics)); var propertyGroup = new BuildPropertyGroup(); propertyGroup.SetProperty("DesignTimeBuild", "true"); propertyGroup.SetProperty("BuildProjectReferences", "false"); // Dump entire assembly reference closure propertyGroup.SetProperty("_ResolveReferenceDependencies", "true"); propertyGroup.SetProperty("SolutionDir", solutionDirectory + Path.DirectorySeparatorChar); // propertyGroup.SetProperty("MSBUILDENABLEALLPROPERTYFUNCTIONS", "1"); engine.GlobalProperties = propertyGroup; var project = engine.CreateNewProject(); project.Load(projectFilePath); var buildResult = engine.BuildProjectFile(projectFilePath, new[] { "ResolveReferences" }, propertyGroup, null, BuildSettings.None, null); if (!buildResult) { return null; } var itemsLookup = project.EvaluatedItems.OfType<BuildItem>() .ToLookup(g => g.Name); var properties = project.EvaluatedProperties.OfType<BuildProperty>() .ToDictionary(p => p.Name); projectFileInfo.AssemblyName = properties["AssemblyName"].FinalValue; projectFileInfo.Name = Path.GetFileNameWithoutExtension(projectFilePath); projectFileInfo.TargetFramework = new FrameworkName(properties["TargetFrameworkMoniker"].FinalValue); if (properties.ContainsKey("LangVersion")) { projectFileInfo.SpecifiedLanguageVersion = ToLanguageVersion(properties["LangVersion"].FinalValue); } projectFileInfo.ProjectId = new Guid(properties["ProjectGuid"].FinalValue.TrimStart('{').TrimEnd('}')); projectFileInfo.TargetPath = properties["TargetPath"].FinalValue; // REVIEW: FullPath here returns the wrong physical path, we need to figure out // why. We must be setting up something incorrectly projectFileInfo.SourceFiles = itemsLookup["Compile"] .Select(b => Path.GetFullPath(Path.Combine(projectFileInfo.ProjectDirectory, b.FinalItemSpec))) .ToList(); projectFileInfo.References = itemsLookup["ReferencePath"] .Where(p => !p.HasMetadata("Project")) .Select(p => Path.GetFullPath(Path.Combine(projectFileInfo.ProjectDirectory, p.FinalItemSpec))) .ToList(); projectFileInfo.ProjectReferences = itemsLookup["ProjectReference"] .Select(p => Path.GetFullPath(Path.Combine(projectFileInfo.ProjectDirectory, p.FinalItemSpec))) .ToList(); projectFileInfo.Analyzers = itemsLookup["Analyzer"] .Select(p => Path.GetFullPath(Path.Combine(projectFileInfo.ProjectDirectory, p.FinalItemSpec))) .ToList(); var allowUnsafe = properties["AllowUnsafeBlocks"].FinalValue; if (!string.IsNullOrWhiteSpace(allowUnsafe)) { projectFileInfo.AllowUnsafe = Convert.ToBoolean(allowUnsafe); } var defineConstants = properties["DefineConstants"].FinalValue; if (!string.IsNullOrWhiteSpace(defineConstants)) { projectFileInfo.DefineConstants = defineConstants.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); } } #else // TODO: Shell out to msbuild/xbuild here? #endif return projectFileInfo; }
public int Main(string[] args) { #if DEBUG if (args.Contains("--debug")) { args = args.Skip(1).ToArray(); System.Diagnostics.Debugger.Launch(); } #endif // Set up logging _log = new CommandOutputLogger(); var app = new CommandLineApplication(); app.Name = "nuget3"; app.FullName = ".NET Package Manager"; app.HelpOption("-h|--help"); app.VersionOption("--version", GetType().GetTypeInfo().Assembly.GetName().Version.ToString()); app.Command("restore", restore => { restore.Description = "Restores packages for a project and writes a lock file"; var sources = restore.Option("-s|--source <source>", "Specifies a NuGet package source to use during the restore", CommandOptionType.MultipleValue); var packagesDirectory = restore.Option("--packages <packagesDirectory>", "Directory to install packages in", CommandOptionType.SingleValue); var parallel = restore.Option("-p|--parallel <noneOrNumberOfParallelTasks>", $"The number of concurrent tasks to use when restoring. Defaults to {RestoreRequest.DefaultDegreeOfConcurrency}; pass 'none' to run without concurrency.", CommandOptionType.SingleValue); var projectFile = restore.Argument("[project file]", "The path to the project to restore for, either a project.json or the directory containing it. Defaults to the current directory"); restore.OnExecute(async () => { // Figure out the project directory IEnumerable<string> externalProjects = null; PackageSpec project; var projectPath = Path.GetFullPath(projectFile.Value ?? "."); if (string.Equals(PackageSpec.PackageSpecFileName, Path.GetFileName(projectPath), StringComparison.OrdinalIgnoreCase)) { _log.LogVerbose($"Reading project file {projectFile.Value}"); projectPath = Path.GetDirectoryName(projectPath); project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(projectFile.Value), Path.GetFileName(projectPath), projectFile.Value); } else if (MsBuildUtility.IsMsBuildBasedProject(projectPath)) { #if DNXCORE50 throw new NotSupportedException(); #else externalProjects = MsBuildUtility.GetProjectReferences(projectPath); projectPath = Path.GetDirectoryName(Path.GetFullPath(projectPath)); var packageSpecFile = Path.Combine(projectPath, PackageSpec.PackageSpecFileName); project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(packageSpecFile), Path.GetFileName(projectPath), projectFile.Value); _log.LogVerbose($"Reading project file {projectFile.Value}"); #endif } else { var file = Path.Combine(projectPath, PackageSpec.PackageSpecFileName); _log.LogVerbose($"Reading project file {file}"); project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(file), Path.GetFileName(projectPath), file); } _log.LogVerbose($"Loaded project {project.Name} from {project.FilePath}"); // Resolve the root directory var rootDirectory = PackageSpecResolver.ResolveRootDirectory(projectPath); _log.LogVerbose($"Found project root directory: {rootDirectory}"); // Resolve the packages directory var packagesDir = packagesDirectory.HasValue() ? packagesDirectory.Value() : Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), ".nuget", "packages"); _log.LogVerbose($"Using packages directory: {packagesDir}"); var packageSources = sources.Values.Select(s => new PackageSource(s)); if (!packageSources.Any()) { var settings = Settings.LoadDefaultSettings(projectPath, configFileName: null, machineWideSettings: null); var packageSourceProvider = new PackageSourceProvider(settings); packageSources = packageSourceProvider.LoadPackageSources(); } var request = new RestoreRequest( project, packageSources, packagesDir); if (externalProjects != null) { foreach (var externalReference in externalProjects) { request.ExternalProjects.Add( new ExternalProjectReference( externalReference, Path.Combine(Path.GetDirectoryName(externalReference), PackageSpec.PackageSpecFileName), projectReferences: Enumerable.Empty<string>())); } } // Run the restore if (parallel.HasValue()) { int parallelDegree; if (string.Equals(parallel.Value(), "none", StringComparison.OrdinalIgnoreCase)) { request.MaxDegreeOfConcurrency = 1; } else if (int.TryParse(parallel.Value(), out parallelDegree)) { request.MaxDegreeOfConcurrency = parallelDegree; } } if (request.MaxDegreeOfConcurrency <= 1) { _log.LogInformation("Running non-parallel restore"); } else { _log.LogInformation($"Running restore with {request.MaxDegreeOfConcurrency} concurrent jobs"); } var command = new RestoreCommand(_log); var sw = Stopwatch.StartNew(); var result = await command.ExecuteAsync(request); sw.Stop(); _log.LogInformation($"Restore completed in {sw.ElapsedMilliseconds:0.00}ms!"); return 0; }); }); app.Command("diag", diag => { diag.Description = "Diagnostic commands for debugging package dependency graphs"; diag.Command("lockfile", lockfile => { lockfile.Description = "Dumps data from the project lock file"; var project = lockfile.Option("--project <project>", "Path containing the project lockfile, or the patht to the lockfile itself", CommandOptionType.SingleValue); var target = lockfile.Option("--target <target>", "View information about a specific project target", CommandOptionType.SingleValue); var library = lockfile.Argument("<library>", "Optionally, get detailed information about a specific library"); lockfile.OnExecute(() => { var diagnostics = new DiagnosticCommands(_log); var projectFile = project.HasValue() ? project.Value() : Path.GetFullPath("."); return diagnostics.Lockfile(projectFile, target.Value(), library.Value); }); }); diag.OnExecute(() => { diag.ShowHelp(); return 0; }); }); app.OnExecute(() => { app.ShowHelp(); return 0; }); return app.Execute(args); }
Action GetContentLoader(HawkOptions options, IHostingEnvironment env, IMemoryCache cache, ILogger logger) { if (options.PostRepostitory == HawkOptions.PostRepositoryOptions.FileSystem) { if (env.IsDevelopment() == false) { throw new Exception("FileSystem repository can only be used in development environment."); } var path = options.FileSystemPath; logger.LogInformation("Loading posts from {path}", path); return () => MemoryCachePostRepository.UpdateCache(cache, FileSystemRepo.EnumeratePosts(path)); } if (options.PostRepostitory == HawkOptions.PostRepositoryOptions.Azure) { var account = Azure.CloudStorageAccount.Parse(options.AzureConnectionString); if (env.IsDevelopment() == false && account.Credentials.AccountName == "devstoreaccount1") { throw new Exception("Azure DevelopmentStorageAccount can only be used in development environment."); } logger.LogInformation($"Loading posts from Azure ({account.Credentials.AccountName})"); return () => { // TODO: investiage if there is a better way to handle async operations during setup var loadTask = AzureRepo.LoadFromAzureAsync(account); var posts = loadTask.GetAwaiter().GetResult(); MemoryCachePostRepository.UpdateCache(cache, posts); }; } throw new Exception("Invalid PostRepostitory configuration setting"); }
static string GetRedirectUrl(HttpRequest req, ILogger logger) { // All dasBlog urls end with .aspx. Bail out immediately for URLs that don't end in .aspx if (req.Path.HasValue && req.Path.Value.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase)) { var repo = req.HttpContext.ApplicationServices.GetRequiredService<IPostRepository>(); logger.LogInformation("Checking {Path}{QueryString}", req.Path, req.QueryString); var redirectUrl = GetRedirector(logger, repo)(req.Path.Value, req.Query.Get); if (redirectUrl == null) { logger.LogError("Could not match {Path}{QueryString}", req.Path, req.QueryString); } return redirectUrl; } return null; }
public virtual int ExecuteTransaction(IEnumerable<IUpdateEntry> entries, ILogger<InMemoryDatabase> logger) { var rowsAffected = 0; lock (_lock) { foreach (var entry in entries) { var entityType = entry.EntityType; Debug.Assert(!entityType.IsAbstract()); IInMemoryTable table; if (!_tables.Value.TryGetValue(entityType, out table)) { _tables.Value.Add(entityType, table = _tableFactory.Create(entityType)); } switch (entry.EntityState) { case EntityState.Added: table.Create(entry); break; case EntityState.Deleted: table.Delete(entry); break; case EntityState.Modified: table.Update(entry); break; } rowsAffected++; } } logger.LogInformation<object>( InMemoryLoggingEventId.SavedChanges, rowsAffected, InMemoryStrings.LogSavedChanges); return rowsAffected; }
internal static async Task InstallFromStream( Stream stream, LibraryIdentity library, string packagesDirectory, ILogger log) { var packagePathResolver = new DefaultPackagePathResolver(packagesDirectory); var targetPath = packagePathResolver.GetInstallPath(library.Name, library.Version); var targetNuspec = packagePathResolver.GetManifestFilePath(library.Name, library.Version); var targetNupkg = packagePathResolver.GetPackageFilePath(library.Name, library.Version); var hashPath = packagePathResolver.GetHashPath(library.Name, library.Version); // Acquire the lock on a nukpg before we extract it to prevent the race condition when multiple // processes are extracting to the same destination simultaneously await ConcurrencyUtilities.ExecuteWithFileLocked(targetNupkg, async createdNewLock => { // If this is the first process trying to install the target nupkg, go ahead // After this process successfully installs the package, all other processes // waiting on this lock don't need to install it again. if (createdNewLock && !File.Exists(targetNupkg)) { log.LogInformation($"Installing {library.Name} {library.Version}"); Directory.CreateDirectory(targetPath); using (var nupkgStream = new FileStream( targetNupkg, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, bufferSize: 4096, useAsync: true)) { await stream.CopyToAsync(nupkgStream); nupkgStream.Seek(0, SeekOrigin.Begin); ExtractPackage(targetPath, nupkgStream); } // DNU REFACTORING TODO: delete the hacky FixNuSpecIdCasing() and uncomment logic below after we // have implementation of NuSpecFormatter.Read() // Fixup the casing of the nuspec on disk to match what we expect var nuspecFile = Directory.EnumerateFiles(targetPath, "*" + ManifestExtension).Single(); FixNuSpecIdCasing(nuspecFile, targetNuspec, library.Name); /*var actualNuSpecName = Path.GetFileName(nuspecFile); var expectedNuSpecName = Path.GetFileName(targetNuspec); if (!string.Equals(actualNuSpecName, expectedNuSpecName, StringComparison.Ordinal)) { MetadataBuilder metadataBuilder = null; var nuspecFormatter = new NuSpecFormatter(); using (var nuspecStream = File.OpenRead(nuspecFile)) { metadataBuilder = nuspecFormatter.Read(nuspecStream); // REVIEW: any way better hardcoding "id"? metadataBuilder.SetMetadataValue("id", library.Name); } // Delete the previous nuspec file File.Delete(nuspecFile); // Write the new manifest using (var targetNuspecStream = File.OpenWrite(targetNuspec)) { nuspecFormatter.Save(metadataBuilder, targetNuspecStream); } }*/ stream.Seek(0, SeekOrigin.Begin); string packageHash; using (var sha512 = SHA512.Create()) { packageHash = Convert.ToBase64String(sha512.ComputeHash(stream)); } // Note: PackageRepository relies on the hash file being written out as the final operation as part of a package install // to assume a package was fully installed. File.WriteAllText(hashPath, packageHash); } return 0; }); }
protected virtual void ConfigureLogging(IApplicationBuilder app) { var hostingEnvironment = app.ApplicationServices.GetRequiredService<IHostingEnvironment>(); var applicationEnvironment = app.ApplicationServices.GetRequiredService<IApplicationEnvironment>(); var loggerFactory = app.ApplicationServices.GetRequiredService<LoggerFactory>(); var nlogConfigFileGenerated = false; var nlogConfigFilename = "NLog.config"; var nlogConfigSearchPaths = new string[] { ".", applicationEnvironment.ApplicationBasePath }; var nlogConfigFilePath = PathUtils.FindPath(nlogConfigSearchPaths, nlogConfigFilename); // If no NLog.config file is found, generate one to use. // The stub is created so that admins can edit and configure // logging even in cases where a file was not provided. if (nlogConfigFilePath == null) { nlogConfigFileGenerated = true; nlogConfigFilePath = Path.Combine(applicationEnvironment.ApplicationBasePath, "NLog.config"); File.WriteAllText(nlogConfigFilePath, @"<?xml version=""1.0"" encoding=""utf-8"" ?> <nlog xmlns=""http://www.nlog-project.org/schemas/NLog.xsd"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" autoReload=""true"" > <targets> <target name=""Console"" xsi:type=""ColoredConsole"" layout=""[${pad:padding=7:inner=${level:uppercase=true}}] ${logger}: ${message}""/> </targets> <rules> <logger name=""*"" minlevel=""Info"" writeTo=""console"" /> </rules> </nlog> "); } var nlogFactory = new NLog.LogFactory(new XmlLoggingConfiguration(nlogConfigFilePath) { AutoReload = true }); loggerFactory.AddNLog(nlogFactory); ApplicationLog = loggerFactory.CreateLogger("Application"); ApplicationLog.LogInformation("Log file opened at {0}.", DateTime.Now); if (nlogConfigFileGenerated) { ApplicationLog.LogWarning("NLog configuration file could not be found. A new one has been generated."); } ApplicationLog.LogInformation("Logging configuration file: {0}", nlogConfigFilePath); AccessLog = loggerFactory.CreateLogger("Access"); AccessLog.LogInformation("Log file opened at {0}.", DateTime.Now); HtmlAccessLog = loggerFactory.CreateLogger("HtmlAccess"); HtmlAccessLog.LogInformation("Log file opened at {0}.", DateTime.Now); }
public Leader(IElection election, IHartbeatTimer hartbeat, IObservable<AppendEntryResultMessage> reply, IObserver<AppendEntryMessage> append, IObserver<ClientResultMessage> clientReply, IObservable<ClientMessage> client, ILogReplication logReplication, Nodes nodes, ILoggerFactory loggerFactory, RaftOptions options, ServerIdentifier serverIdentifier) { _isDispose = false; _hartbeat = hartbeat; _append = append; _clientReply = clientReply; _client = client; _logReplication = logReplication; _nodes = nodes; _options = options; _serverIdentifier = serverIdentifier; _election = election; _logger = loggerFactory.CreateLogger(nameof(Leader) + " " + serverIdentifier); if (_options.UseLogging) _logger.LogInformation($"{nameof(ServerStateType.Leader)}"); // Reinitialized after election NextIndex = new ConcurrentDictionary<ServerIdentifier, int>(); MatchIndex = new ConcurrentDictionary<ServerIdentifier, int>(); _hartbeat.Leader(SendHartbeat); _replyDispose = reply.Subscribe(EntryReplyMessageRecived); _clientReplyDispose = client.Subscribe(ClientMessageRecived); }
/// <summary> /// Retries every 1 sec for 60 times by default. /// </summary> /// <param name="retryBlock"></param> /// <param name="logger"></param> /// <param name="cancellationToken"></param> /// <param name="retryCount"></param> public static async Task<HttpResponseMessage> RetryRequest( Func<Task<HttpResponseMessage>> retryBlock, ILogger logger, CancellationToken cancellationToken = default(CancellationToken), int retryCount = 60) { for (int retry = 0; retry < retryCount; retry++) { if (cancellationToken.IsCancellationRequested) { logger.LogInformation("Failed to connect, retry canceled."); throw new OperationCanceledException("Failed to connect, retry canceled.", cancellationToken); } try { logger.LogWarning("Retry count {retryCount}..", retry + 1); var response = await retryBlock(); if (response.StatusCode == HttpStatusCode.ServiceUnavailable) { // Automatically retry on 503. May be application is still booting. logger.LogWarning("Retrying a service unavailable error."); continue; } return response; // Went through successfully } catch (Exception exception) { if (retry == retryCount - 1) { logger.LogError("Failed to connect, retry limit exceeded.", exception); throw; } else { if (exception is HttpRequestException #if DNX451 || exception is System.Net.WebException #endif ) { logger.LogWarning("Failed to complete the request : {0}.", exception.Message); await Task.Delay(1 * 1000); //Wait for a while before retry. } } } } logger.LogInformation("Failed to connect, retry limit exceeded."); throw new OperationCanceledException("Failed to connect, retry limit exceeded."); }
// 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) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); _logger = loggerFactory.CreateLogger("Test"); _logger.LogInformation("Starting Jacks logging"); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseIISPlatformHandler(); app.UseStaticFiles(); app.UseSignalR2(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); _dm = new DownloadManager(_logger, GlobalHost.ConnectionManager.GetHubContext<Scraper.Hubs.ChatHub>()); Console.CancelKeyPress += (s,e) => { _logger.LogInformation("CTRL+C detected - shutting down"); _dm.Stop(); }; }