/// <summary> /// Starts the Logger for the specified file path and log level. /// </summary> /// <param name="logFilePath">The path of the log file to be written.</param> /// <param name="logLevel">The minimum level of log messages to be written.</param> public void StartLogging(string logFilePath, PsesLogLevel logLevel) { Log.Logger = new LoggerConfiguration().Enrich.FromLogContext() .WriteTo.File(logFilePath) .MinimumLevel.Verbose() .CreateLogger(); _factory = new LoggerFactory().AddSerilog(Log.Logger); _logger = _factory.CreateLogger <EditorServicesHost>(); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location); string osVersion = RuntimeInformation.OSDescription; string osArch = GetOSArchitecture(); string buildTime = BuildInfo.BuildTime?.ToString("s", System.Globalization.CultureInfo.InvariantCulture) ?? "<unspecified>"; string logHeader = $@" PowerShell Editor Services Host v{fileVersionInfo.FileVersion} starting (PID {Process.GetCurrentProcess().Id}) Host application details: Name: {_hostDetails.Name} Version: {_hostDetails.Version} ProfileId: {_hostDetails.ProfileId} Arch: {osArch} Operating system details: Version: {osVersion} Arch: {osArch} Build information: Version: {BuildInfo.BuildVersion} Origin: {BuildInfo.BuildOrigin} Date: {buildTime} "; _logger.LogInformation(logHeader); }
public static LogLevel ToExtensionsLogLevel(this PsesLogLevel logLevel) { switch (logLevel) { case PsesLogLevel.Diagnostic: return(LogLevel.Trace); case PsesLogLevel.Verbose: return(LogLevel.Debug); case PsesLogLevel.Normal: return(LogLevel.Information); case PsesLogLevel.Warning: return(LogLevel.Warning); case PsesLogLevel.Error: return(LogLevel.Error); default: return(LogLevel.Information); } }