Skip to content

Commit

Permalink
[SQ] CA2253 - Named placeholders in the logging message template shou…
Browse files Browse the repository at this point in the history
…ld not be comprised of only numeric characters
  • Loading branch information
samatrhea committed Dec 17, 2023
1 parent 9c129d4 commit 5728cb0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions CometServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public static async Task<int> Main(string[] args)

if (!dataStoreAvailable)
{
logger.LogCritical("The CDP4-COMET REST API has terminated - The data-store was not availble within the configured BacktierWaitTime: {0}", appConfigService.AppConfig.Midtier.BacktierWaitTime);
logger.LogCritical("The CDP4-COMET REST API has terminated - The data-store was not availble within the configured BacktierWaitTime: {BacktierWaitTime}", appConfigService.AppConfig.Midtier.BacktierWaitTime);
return 0;
}

logger.LogInformation("The data-store has become available for connections within the configured BacktierWaitTime: {0}", appConfigService.AppConfig.Midtier.BacktierWaitTime);
logger.LogInformation("The data-store has become available for connections within the configured BacktierWaitTime: {BacktierWaitTime}", appConfigService.AppConfig.Midtier.BacktierWaitTime);

var migrationEngine = host.Services.GetService<IMigrationEngine>();
migrationEngine.MigrateAllAtStartUp();
Expand All @@ -128,7 +128,7 @@ public static async Task<int> Main(string[] args)
var configuration = host.Services.GetService<IConfiguration>();
var uri = configuration.GetSection("Kestrel:Endpoints:Http:Url").Value;

logger.LogInformation("CDP4-COMET REST API Ready to accept connections at {0}", uri);
logger.LogInformation("CDP4-COMET REST API Ready to accept connections at {uri}", uri);

await host.RunAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void Load(NpgsqlTransaction transaction, ISecurityContext securityContext
this.parameterTypeAssignmentCache.Add(kvp.Key, kvp.Value);
}

this.Logger.LogTrace("Cache initialized with {0} ParameterTypes, {1} DependentParameterTypeAssignments, {2} IndependentParameterTypeAssignments and {3} ParameterTypeComponents in {4}",
this.Logger.LogTrace("Cache initialized with {parameterTypeCache} ParameterTypes, {dependentParameterTypeAssignments} DependentParameterTypeAssignments, {independentParameterTypeAssignments} IndependentParameterTypeAssignments and {parameterTypeComponentCache} ParameterTypeComponents in {ElapsedMilliseconds}",
this.parameterTypeCache.Count,
dependentParameterTypeAssignments.Count,
independentParameterTypeAssignments.Count,
Expand Down
8 changes: 4 additions & 4 deletions CometServer/Services/BusinessLogic/FileBinaryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ public void StoreBinaryData(string hash, Stream data)
var sw = new Stopwatch();
sw.Start();

this.Logger.LogDebug("Store Binary Data with hash: {0} started", hash);
this.Logger.LogDebug("Store Binary Data with hash: {hash} started", hash);

string filePath;
if (this.TryGetFileStoragePath(hash, out filePath))
{
this.Logger.LogDebug("The file already exists: {0}/{1}", filePath, hash);
this.Logger.LogDebug("The file already exists: {filePath}/{hash}", filePath, hash);

// return as file already exists
sw.Stop();
Expand All @@ -130,15 +130,15 @@ public void StoreBinaryData(string hash, Stream data)
// create the path for the file
var stroragePath = this.GetBinaryStoragePath(hash, true);
filePath = Path.Combine(stroragePath, hash);
this.Logger.LogDebug("New File storage path: ", filePath);
this.Logger.LogDebug("New File storage path: {filePath}", filePath);

using (var fileStream = File.Create(filePath))
{
data.Seek(0, SeekOrigin.Begin);
data.CopyTo(fileStream);
}

this.Logger.LogDebug("File {0} stored in {1} [ms]", filePath, sw.ElapsedMilliseconds);
this.Logger.LogDebug("File {filePath} stored in {ElapsedMilliseconds} [ms]", filePath, sw.ElapsedMilliseconds);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public bool CheckConnection()
}
catch (Exception)
{
this.Logger.LogInformation("Waiting for the data store at {0}:{1} to become availble in {2} [s]",
this.Logger.LogInformation("Waiting for the data store at {HostName}:{Port} to become availble in {remainingSeconds} [s]",
this.AppConfigService.AppConfig.Backtier.HostName,
this.AppConfigService.AppConfig.Backtier.Port,
remainingSeconds);
Expand Down
26 changes: 13 additions & 13 deletions CometServer/Services/JsonExchangeFile/JsonExchangeFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private static MemoryStream ReadFileToMemory(string filePath)
var siteDirectoryZipEntry = zip.Entries.SingleOrDefault(x => x.FileName.EndsWith("SiteDirectory.json"));

var returnedSiteDirectory = this.ReadInfoFromArchiveEntry(version, siteDirectoryZipEntry, password);
this.Logger.LogInformation("{0} Site Directory item(s) encountered", returnedSiteDirectory.Count);
this.Logger.LogInformation("{count} Site Directory item(s) encountered", returnedSiteDirectory.Count);

var returned = new List<CDP4Common.DTO.Thing>(returnedSiteDirectory);
var processedRdls = new List<string>();
Expand All @@ -230,15 +230,15 @@ var engineeringModelSetup in
var modelRdlZipEntry = zip.Entries.SingleOrDefault(x => x.FileName.EndsWith(modelRdlFilePath));
var modelRdlItems = this.ReadInfoFromArchiveEntry(version, modelRdlZipEntry, password);

this.Logger.LogInformation("{0} Model Reference Data Library item(s) encountered", returnedSiteDirectory.Count);
this.Logger.LogInformation("{Count} Model Reference Data Library item(s) encountered", returnedSiteDirectory.Count);
returned.AddRange(modelRdlItems);

// load the reference data libraries as per the containment chain
var requiredRdl = modelRdlDto.RequiredRdl;

while (requiredRdl != null)
{
this.Logger.LogInformation("Required Reference Data Library encountered: {0}", requiredRdl);
this.Logger.LogInformation("Required Reference Data Library encountered: {requiredRdl}", requiredRdl);

var siteRdlDto =
(SiteReferenceDataLibrary)
Expand All @@ -254,7 +254,7 @@ var engineeringModelSetup in

var siteRdlItems = this.ReadInfoFromArchiveEntry(version, siteRdlZipEntry, password);

this.Logger.LogInformation("{0} Site Reference Data Library item(s) encountered", siteRdlItems.Count);
this.Logger.LogInformation("{Count} Site Reference Data Library item(s) encountered", siteRdlItems.Count);
returned.AddRange(siteRdlItems);

// register this processedRdl
Expand All @@ -266,7 +266,7 @@ var engineeringModelSetup in
}
}

this.Logger.LogInformation("{0} Site Directory items encountered", returned.Count);
this.Logger.LogInformation("{Count} Site Directory items encountered", returned.Count);
return returned;
}
}
Expand Down Expand Up @@ -312,13 +312,13 @@ var engineeringModelSetup in
var engineeringModelZipEntry = zip.Entries.SingleOrDefault(x => x.FileName.EndsWith(engineeringModelFilePath));
var engineeringModelItems = this.ReadInfoFromArchiveEntry(version, engineeringModelZipEntry, password);

this.Logger.LogInformation("{0} Engineering Model item(s) encountered", engineeringModelItems.Count);
this.Logger.LogInformation("{Count} Engineering Model item(s) encountered", engineeringModelItems.Count);
return engineeringModelItems;
}
}
catch (Exception ex)
{
var msg = string.Format("{0}: {1}", "Failed to load file. Error", ex.Message);
var msg = $"Failed to load file. Error: {ex.Message}";
this.Logger.LogError(msg);

throw new FileLoadException(msg);
Expand Down Expand Up @@ -358,13 +358,13 @@ var engineeringModelSetup in
var iterationZipEntry = zip.Entries.SingleOrDefault(x => x.FileName.EndsWith(iterationFilePath));
var iterationItems = this.ReadInfoFromArchiveEntry(version, iterationZipEntry, password);

this.Logger.LogInformation("{0} Iteration item(s) encountered", iterationItems.Count);
this.Logger.LogInformation("{Count} Iteration item(s) encountered", iterationItems.Count);
return iterationItems;
}
}
catch (Exception ex)
{
var msg = string.Format("{0}: {1}", "Failed to load file. Error", ex.Message);
var msg = $"Failed to load file. Error: {ex.Message}";
this.Logger.LogError(msg);

throw new FileLoadException(msg);
Expand Down Expand Up @@ -398,7 +398,7 @@ private void ExtractFileBinaryByHash(MemoryStream archiveStream, string archiveP

using (var stream = this.ReadStreamFromArchive(fileZipEntry, archivePassword))
{
this.Logger.LogInformation("Store file binary with hash {0}", hash);
this.Logger.LogInformation("Store file binary with hash {hash}", hash);
this.FileBinaryService.StoreBinaryData(hash, stream);
}
}
Expand Down Expand Up @@ -433,7 +433,7 @@ private void ExtractFileBinaryByHash(MemoryStream archiveStream, string archiveP
}

watch.Stop();
this.Logger.LogInformation("JSON Deserializer completed in {0} ", watch.Elapsed);
this.Logger.LogInformation("JSON Deserializer completed in {ElapsedMilliseconds} [ms]", watch.ElapsedMilliseconds);
return returned.ToList();
}

Expand Down Expand Up @@ -470,14 +470,14 @@ private Stream ReadStreamFromArchive(ZipEntry zipEntry, string archivePassword)
}
catch (Exception ex)
{
var msg = $"{"Failed to open file. Error"}: {ex.Message}";
var msg = $"Failed to open file. Error: {ex.Message}";
this.Logger.LogError(msg);

throw new FileLoadException(msg);
}

watch.Stop();
this.Logger.LogInformation("JSONFile GET completed in {0} ", watch.Elapsed);
this.Logger.LogInformation("JSONFile GET completed in {ElapsedMilliseconds} [ms]", watch.ElapsedMilliseconds);

return new MemoryStream(extractStream.ToArray());
}
Expand Down
14 changes: 7 additions & 7 deletions CometServer/Services/Operations/ModelCreatorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,18 @@ public void CopyEngineeringModelData(EngineeringModelSetup newModelSetup, Npgsql
this.DisableUserTrigger(transaction);

// copy all data from the source to the target partition
this.Logger.LogDebug("Copy EngineeringModel data from {0} to {1}", sourcePartition, targetPartition);
this.Logger.LogDebug("Copy EngineeringModel data from {sourcePartition} to {targetPartition}", sourcePartition, targetPartition);
this.EngineeringModelService.CopyEngineeringModel(transaction, sourcePartition, targetPartition);
this.Logger.LogDebug("Copy Iteration data from {0} to {1}", sourceIterationPartition, targetIterationPartition);
this.Logger.LogDebug("Copy Iteration data from {sourceIterationPartition} to {targetIterationPartition}", sourceIterationPartition, targetIterationPartition);
this.IterationService.CopyIteration(transaction, sourceIterationPartition, targetIterationPartition);

// wipe the organizational participations
this.IterationService.DeleteAllrganizationalParticipantThings(transaction, targetIterationPartition);

// change id on Thing table for all other things
this.Logger.LogDebug("Modify Identifiers of EngineeringModel {0} data", targetPartition);
this.Logger.LogDebug("Modify Identifiers of EngineeringModel {targetPartition} data", targetPartition);
this.EngineeringModelService.ModifyIdentifier(transaction, targetPartition);
this.Logger.LogDebug("Modify Identifiers of Iteration {0} data", targetIterationPartition);
this.Logger.LogDebug("Modify Identifiers of Iteration {targetIterationPartition} data", targetIterationPartition);
this.EngineeringModelService.ModifyIdentifier(transaction, targetIterationPartition);

// update iid for engineering-model and iteration(s)
Expand All @@ -238,7 +238,7 @@ public void CopyEngineeringModelData(EngineeringModelSetup newModelSetup, Npgsql
newEngineeringModel.Iid = newModelSetup.EngineeringModelIid;
newEngineeringModel.EngineeringModelSetup = newModelSetup.Iid;

this.Logger.LogDebug("Modify Identifier of new EngineeringModel {0} to {1}", oldIid, newModelSetup.EngineeringModelIid);
this.Logger.LogDebug("Modify Identifier of new EngineeringModel {oldIid} to {EngineeringModelIid}", oldIid, newModelSetup.EngineeringModelIid);
this.EngineeringModelService.ModifyIdentifier(transaction, targetPartition, newEngineeringModel, oldIid);

if (!this.EngineeringModelService.UpdateConcept(transaction, targetPartition, newEngineeringModel, null))
Expand All @@ -251,7 +251,7 @@ public void CopyEngineeringModelData(EngineeringModelSetup newModelSetup, Npgsql
modelThings.AddRange(this.IterationService.GetDeep(transaction, targetPartition, null, securityContext));

var sw = Stopwatch.StartNew();
this.Logger.LogDebug("start modify {0} references of things contained in the new engineering-model-setup (rdl included)", modelThings.Count);
this.Logger.LogDebug("start modify {Count} references of things contained in the new engineering-model-setup (rdl included)", modelThings.Count);
foreach (var modelThing in modelThings)
{
var model = modelThing as EngineeringModel;
Expand Down Expand Up @@ -304,7 +304,7 @@ public void CopyEngineeringModelData(EngineeringModelSetup newModelSetup, Npgsql
}
}

this.Logger.LogDebug("modified {modelThings.Count} references of things contained in the new engineering-model-setup in {sw} [ms]", modelThings.Count, sw.ElapsedMilliseconds);
this.Logger.LogDebug("modified {Count} references of things contained in the new engineering-model-setup in {Count} [ms]", modelThings.Count, sw.ElapsedMilliseconds);

// IMPORTANT: re-enable user trigger once the current transaction is commited commited
}
Expand Down

0 comments on commit 5728cb0

Please sign in to comment.