Added dev and prod files for logger

This commit is contained in:
Alex
2025-04-24 16:44:56 +01:00
parent 222ca2e274
commit d7e67af662
4 changed files with 92 additions and 7 deletions
@@ -12,7 +12,8 @@ public class SptLogger<T> : ISptLogger<T>, IDisposable
private readonly SptLoggerQueueManager _loggerQueueManager;
private const string ConfigurationPath = "./sptLogger.json";
private readonly SptLoggerConfiguration _config;
private const string ConfigurationPathDev = "./sptLogger.Development.json";
private SptLoggerConfiguration _config;
~SptLogger()
{
@@ -24,13 +25,13 @@ public class SptLogger<T> : ISptLogger<T>, IDisposable
_category = typeof(T).FullName;
_loggerQueueManager = loggerQueueManager;
if (fileUtil.FileExists(ConfigurationPath))
if (ProgramStatics.DEBUG())
{
_config = jsonUtil.DeserializeFromFile<SptLoggerConfiguration>(ConfigurationPath);
LoadConfig(fileUtil, jsonUtil, ConfigurationPathDev);
}
else
{
throw new Exception($"Unable to find SPTLogger file '{ConfigurationPath}'");
LoadConfig(fileUtil, jsonUtil, ConfigurationPath);
}
if (_config == null)
@@ -42,6 +43,18 @@ public class SptLogger<T> : ISptLogger<T>, IDisposable
_loggerQueueManager.Initialize(_config);
}
private void LoadConfig(FileUtil fileUtil, JsonUtil jsonUtil, string sptloggerDevelopmentJson)
{
if (fileUtil.FileExists(sptloggerDevelopmentJson))
{
_config = jsonUtil.DeserializeFromFile<SptLoggerConfiguration>(sptloggerDevelopmentJson);
}
else
{
throw new Exception($"Unable to find SPTLogger file '{sptloggerDevelopmentJson}'");
}
}
public void OverrideCategory(string category)
{
_category = category;
+3 -2
View File
@@ -36,11 +36,12 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<ExcludeFromSingleFile>True</ExcludeFromSingleFile>
</Content>
<None Remove="appsettings.json"/>
<None Remove="appsettings.Development.json"/>
<None Update="sptLogger.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="sptLogger.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
@@ -0,0 +1,71 @@
{
"loggers": [
{
"type": "File",
"logLevel": "Trace",
"format": "[%date% %time%][%level%][%logger%] %message%",
"filePath": "./user/logs/kestrel/kestrel.txt",
"filters": [
{
"type": "Include",
"name": "Microsoft\\.AspNetCore\\.Server\\.Kestrel.*",
"matchingType": "Regex"
}
]
},
{
"type": "File",
"logLevel": "Trace",
"format": "[%date% %time%][%level%][%logger%] %message%",
"filePath": "./user/logs/spt/spt.txt",
"filters": [
{
"type": "Exclude",
"name": ".*RequestLogger",
"matchingType": "Regex"
},
{
"type": "Exclude",
"name": "Microsoft\\.AspNetCore\\.Server\\.Kestrel.*",
"matchingType": "Regex"
}
]
},
{
"type": "File",
"logLevel": "Trace",
"format": "[%date% %time%][%level%][%logger%] %message%",
"filePath": "./user/logs/requests/requests.txt",
"filters": [
{
"type": "Include",
"name": ".*RequestLogger",
"matchingType": "Regex"
}
]
},
{
"type": "Console",
"logLevel": "Trace",
"format": "%message%",
"filters": [
{
"type": "Exclude",
"name": "Microsoft.*",
"matchingType": "Regex"
},
{
"type": "Exclude",
"name": ".*FileLogger",
"matchingType": "Regex"
},
{
"type": "Exclude",
"name": ".*RequestLogger",
"matchingType": "Regex"
}
]
}
]
}
+1 -1
View File
@@ -33,7 +33,7 @@
},
{
"type": "Console",
"logLevel": "Trace",
"logLevel": "Info",
"format": "%message%",
"filters": [
{