/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/imageresizer/ImageResizerCLI/Program.cs
71 строка
2 KB
Muyuan Li
Add telemetry support for CLI modules (#46872)
15 апр 2026, 09:14
Не верифицирован
15 апр 2026, 09:14
be1e749
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Globalization; using System.Text; using ImageResizer.Cli; using ImageResizer.Cli.Telemetry; using ManagedCommon; using Microsoft.PowerToys.Telemetry; namespace ImageResizerCLI; internal static class Program { private static int Main(string[] args) { try { string appLanguage = LanguageHelper.LoadLanguage(); if (!string.IsNullOrEmpty(appLanguage)) { System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(appLanguage); } } catch (CultureNotFoundException) { // Ignore invalid culture and fall back to default. } Console.InputEncoding = Encoding.Unicode; // Initialize logger to file (same as other modules) CliLogger.Initialize("\\Image Resizer\\CLI"); CliLogger.Info($"ImageResizerCLI started with {args.Length} argument(s)"); try { var executor = new ImageResizerCliExecutor(); int result = executor.Run(args); LogCLITelemetry(executor.CommandName, result == 0); return result; } catch (Exception ex) { CliLogger.Error($"Unhandled exception: {ex.Message}"); CliLogger.Error($"Stack trace: {ex.StackTrace}"); Console.Error.WriteLine($"Fatal error: {ex.Message}"); LogCLITelemetry("resize", successful: false); return 1; } } private static void LogCLITelemetry(string commandName, bool successful) { try { PowerToysTelemetry.Log.WriteEvent(new ImageResizerCLICommandEvent { CommandName = commandName, Successful = successful, }); } catch (Exception ex) { CliLogger.Error($"Failed to log CLI telemetry: {ex.Message}"); } } }