-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: embed version metadata with git information into assembly
- Loading branch information
Showing
15 changed files
with
226 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
Framework/Intersect.Framework/Logging/LoggerConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using Intersect.Framework.Reflection; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
using Serilog.Extensions.Logging; | ||
using ILogger = Microsoft.Extensions.Logging.ILogger; | ||
|
||
namespace Intersect.Framework.Logging; | ||
|
||
public static class LoggerConfigurationExtensions | ||
{ | ||
public static (ILoggerFactory, ILogger) CreateLoggerForIntersect( | ||
this LoggerConfiguration loggerConfiguration, | ||
Assembly forAssembly, | ||
string categoryName, | ||
LoggingLevelSwitch? parentLoggingLevelSwitch = null | ||
) | ||
{ | ||
var currentProcess = Process.GetCurrentProcess(); | ||
var processStartTime = currentProcess.StartTime; | ||
var executableName = Path.GetFileNameWithoutExtension( | ||
currentProcess.MainModule?.FileName ?? forAssembly.GetName().Name | ||
); | ||
|
||
LoggingLevelSwitch loggingLevelSwitch = | ||
new(Debugger.IsAttached ? LogEventLevel.Debug : LogEventLevel.Information); | ||
|
||
if (parentLoggingLevelSwitch is not null) | ||
{ | ||
parentLoggingLevelSwitch.MinimumLevelChanged += | ||
(_, args) => loggingLevelSwitch.MinimumLevel = args.NewLevel; | ||
} | ||
|
||
LoggingLevelSwitch errorLevelSwitch = new(); | ||
|
||
var serilogLogger = loggerConfiguration | ||
.MinimumLevel.ControlledBy(loggingLevelSwitch) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console() | ||
.WriteTo.File( | ||
Path.Combine( | ||
"logs", | ||
$"{executableName}-{processStartTime:yyyy_MM_dd-HH_mm_ss_fff}.log" | ||
), | ||
rollOnFileSizeLimit: true, | ||
retainedFileTimeLimit: TimeSpan.FromDays(30) | ||
) | ||
.WriteTo.File( | ||
Path.Combine("logs", $"errors-{executableName}.log"), | ||
levelSwitch: errorLevelSwitch, | ||
rollOnFileSizeLimit: true, | ||
retainedFileTimeLimit: TimeSpan.FromDays(30) | ||
) | ||
.CreateLogger(); | ||
|
||
var loggerFactory = new SerilogLoggerFactory(serilogLogger, dispose: true); | ||
var logger = loggerFactory.CreateLogger(categoryName); | ||
|
||
logger.LogInformation( | ||
"Starting {AssemblyName} v{AssemblyVersion}", | ||
forAssembly.GetName().Name, | ||
forAssembly.GetMetadataVersion() | ||
); | ||
|
||
errorLevelSwitch.MinimumLevel = LogEventLevel.Error; | ||
|
||
return (loggerFactory, logger); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
using System.Reflection; | ||
using Intersect.Framework.Reflection; | ||
|
||
Console.WriteLine($"Starting {Assembly.GetExecutingAssembly().GetMetadataName()}..."); | ||
|
||
Intersect.Client.Core.Program.Main(args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.