Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger will not try and resolve path if not logging to disk #3496

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions Core/Core/Logging/SpeckleLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,6 @@ public static Logger CreateConfiguredLogger(
SpeckleLogConfiguration logConfiguration
)
{
// TODO: check if we have write permissions to the file.
// if not, disable file sink, even if its enabled in the config
// show a warning about that...
var canLogToFile = true;
s_logFolderPath = SpecklePathProvider.LogFolderPath(hostApplicationName, hostApplicationVersion);
var logFilePath = Path.Combine(s_logFolderPath, "SpeckleCoreLog.txt");

var fileVersionInfo = GetFileVersionInfo();
var serilogLogConfiguration = new LoggerConfiguration().MinimumLevel
.Is(logConfiguration.MinimumLevel)
Expand All @@ -200,8 +193,21 @@ SpeckleLogConfiguration logConfiguration
.Enrich.WithExceptionDetails();
}

if (logConfiguration.LogToFile && canLogToFile)
if (logConfiguration.LogToFile)
{
// TODO: check if we have write permissions to the file.
// if not, disable file sink, even if its enabled in the config
// show a warning about that...
// if (!canLogToFile)
// {
// logger.Warning("Log to file is enabled, but cannot write to {LogFilePath}", logFilePath);
// }
// else
// {

s_logFolderPath = SpecklePathProvider.LogFolderPath(hostApplicationName, hostApplicationVersion);
var logFilePath = Path.Combine(s_logFolderPath, "SpeckleCoreLog.txt");

serilogLogConfiguration = serilogLogConfiguration.WriteTo.File(
logFilePath,
rollingInterval: RollingInterval.Day,
Expand Down Expand Up @@ -253,11 +259,6 @@ SpeckleLogConfiguration logConfiguration

var logger = serilogLogConfiguration.CreateLogger();

if (logConfiguration.LogToFile && !canLogToFile)
{
logger.Warning("Log to file is enabled, but cannot write to {LogFilePath}", logFilePath);
}

if (s_isMachineIdUsed)
{
logger.Warning("Cannot set user id for the global log context.");
Expand Down