Skip to content

Commit

Permalink
add initial log statement and fix log path (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock authored Aug 19, 2024
1 parent 42882cb commit 03a5706
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/Speckle.Sdk.Logging/LogBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static class LogBuilder
if (speckleLogging?.File is not null)
{
// TODO: check if we have write permissions to the file.
var logFilePath = SpecklePathProvider.LogFolderPath(applicationAndVersion, slug);
var logFilePath = SpecklePathProvider.LogFolderPath(applicationAndVersion);
logFilePath = Path.Combine(logFilePath, speckleLogging.File.Path ?? "SpeckleCoreLog.txt");
serilogLogConfiguration = serilogLogConfiguration.WriteTo.File(
logFilePath,
Expand All @@ -71,6 +71,13 @@ public static class LogBuilder
var logger = serilogLogConfiguration.CreateLogger();
Log.Logger = logger;

logger
.ForContext("hostApplication", applicationAndVersion)
.ForContext("userApplicationDataPath", SpecklePathProvider.UserApplicationDataPath())
.ForContext("installApplicationDataPath", SpecklePathProvider.InstallApplicationDataPath)
.Information(
"Initialized logger inside {hostApplication}/{productVersion}/{version} for user {id}. Path info {userApplicationDataPath} {installApplicationDataPath}."
);
return InitializeOtelTracing(speckleTracing, resourceBuilder);
}

Expand Down
18 changes: 4 additions & 14 deletions src/Speckle.Sdk.Logging/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,13 @@ public static string BlobStoragePath(string? path = null)
return EnsureFolderExists(path ?? UserSpeckleFolderPath, s_blobFolderName);
}

private static string EnsureFolderExists(string basePath, string folderName)
private static string EnsureFolderExists(params string[] folderName)
{
var path = System.IO.Path.Combine(basePath, folderName);
var path = System.IO.Path.Combine(folderName);
Directory.CreateDirectory(path);
return path;
}

/// <summary>
/// Get the folder where the Speckle logs should be stored.
/// </summary>
/// <param name="hostApplicationName">Name of the application using this SDK ie.: "Rhino"</param>
/// <param name="hostApplicationVersion">Public version slug of the application using this SDK ie.: "2023"</param>
public static string LogFolderPath(string hostApplicationName, string? hostApplicationVersion)
{
return EnsureFolderExists(
EnsureFolderExists(UserSpeckleFolderPath, LOG_FOLDER_NAME),
$"{hostApplicationName}{hostApplicationVersion ?? ""}"
);
}
internal static string LogFolderPath(string applicationAndVersion) =>
EnsureFolderExists(UserSpeckleFolderPath, LOG_FOLDER_NAME, applicationAndVersion);
}

0 comments on commit 03a5706

Please sign in to comment.