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

Removing some Error meesages that are user based #2223

Merged
merged 6 commits into from
Jul 29, 2024
22 changes: 11 additions & 11 deletions docs/Reference/Generated/MigrationTools.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public void CleanUpAfterSave()
}
catch (Exception ex)
{
Log.LogWarning(" ERROR: Unable to delete folder {0}", _exportWiPath);
Telemetry.TrackException(ex, null, null);
Log.LogWarning(" ERROR: Unable to delete folder {0}! Should be cleaned up at the end.", _exportWiPath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ private NodeInfo GetOrCreateNode(string nodePath, DateTime? startDate, DateTime?
} catch (Exception ex)
{
Log.LogDebug(" Not Found:", currentAncestorPath);
Telemetry.TrackException(ex, null, null);
parentNode = null;
}

Expand All @@ -196,8 +195,8 @@ private NodeInfo GetOrCreateNode(string nodePath, DateTime? startDate, DateTime?

if (parentNode == null)
{
throw new InvalidOperationException(
$"Path {nodePath} is not anchored in the target project, it cannot be created.");
Log.LogCritical($"Path {nodePath} is not anchored in the target project, it cannot be created.");
Environment.Exit(-1);
}

// Now that we have a parent, we can start creating nodes down the tree from that point
Expand Down
38 changes: 27 additions & 11 deletions src/MigrationTools.Host/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using MigrationTools.Host.Services;
Expand All @@ -18,6 +20,7 @@ namespace MigrationTools.Host.Commands
{
internal abstract class CommandBase<TSettings> : AsyncCommand<TSettings> where TSettings : CommandSettingsBase
{
private IServiceProvider _services;
private IMigrationToolVersion _MigrationToolVersion;
private readonly IHostApplicationLifetime _LifeTime;
private readonly IDetectOnlineService _detectOnlineService;
Expand All @@ -26,8 +29,9 @@ internal abstract class CommandBase<TSettings> : AsyncCommand<TSettings> where T
private readonly ITelemetryLogger _telemetryLogger;
private static Stopwatch _mainTimer = new Stopwatch();

public CommandBase(IHostApplicationLifetime appLifetime, IDetectOnlineService detectOnlineService, IDetectVersionService2 detectVersionService, ILogger<CommandBase<TSettings>> logger, ITelemetryLogger telemetryLogger, IMigrationToolVersion migrationToolVersion)
public CommandBase(IHostApplicationLifetime appLifetime, IServiceProvider services, IDetectOnlineService detectOnlineService, IDetectVersionService2 detectVersionService, ILogger<CommandBase<TSettings>> logger, ITelemetryLogger telemetryLogger, IMigrationToolVersion migrationToolVersion)
{
_services = services;
_MigrationToolVersion = migrationToolVersion;
_LifeTime = appLifetime;
_detectOnlineService = detectOnlineService;
Expand All @@ -39,7 +43,11 @@ public CommandBase(IHostApplicationLifetime appLifetime, IDetectOnlineService de
public override async Task<int> ExecuteAsync(CommandContext context, TSettings settings)
{
_mainTimer.Start();
_logger.LogTrace("Starting {CommandName}", this.GetType().Name);
// Disable Telemetry
TelemetryConfiguration ai = _services.GetService<TelemetryConfiguration>();
ai.DisableTelemetry = settings.DisableTelemetry;
// Run the command
Log.Debug("Starting {CommandName}", this.GetType().Name);
_telemetryLogger.TrackEvent(this.GetType().Name);
RunStartupLogic(settings);
try
Expand Down Expand Up @@ -142,23 +150,31 @@ private void ApplicationStartup( TSettings settings)
{
_mainTimer.Start();
AsciiLogo(_MigrationToolVersion.GetRunningVersion().versionString);
TelemetryNote();
TelemetryNote(settings);
_logger.LogInformation("Start Time: {StartTime}", DateTime.Now.ToUniversalTime().ToLocalTime());
_logger.LogInformation("Running with settings: {@settings}", settings);
_logger.LogInformation("OSVersion: {OSVersion}", Environment.OSVersion.ToString());
_logger.LogInformation("Version (Assembly): {Version}", _MigrationToolVersion.GetRunningVersion().versionString);
}

private void TelemetryNote()
private void TelemetryNote(TSettings settings)
{
_logger.LogInformation("--------------------------------------");
_logger.LogInformation("Telemetry Note:");
_logger.LogInformation(" We use Application Insights to collect usage and error information in order to improve the quality of the tools.");
_logger.LogInformation(" Currently we collect the following anonymous data:");
_logger.LogInformation(" -Event data: application version, client city/country, hosting type, item count, error count, warning count, elapsed time.");
_logger.LogInformation(" -Exceptions: application errors and warnings.");
_logger.LogInformation(" -Dependencies: REST/ObjectModel calls to Azure DevOps to help us understand performance issues.");
_logger.LogInformation(" This data is tied to a session ID that is generated on each run of the application and shown in the logs. This can help with debugging. If you want to disable telemetry you can run the tool with '--disableTelemetry' on the command prompt.");
_logger.LogInformation(" Note: Exception data cannot be 100% guaranteed to not leak production data");
if (settings.DisableTelemetry)
{
_logger.LogInformation(" Telemetry is disabled by the user.");
} else
{
_logger.LogInformation(" We use Application Insights to collect usage and error information in order to improve the quality of the tools.");
_logger.LogInformation(" Currently we collect the following anonymous data:");
_logger.LogInformation(" -Event data: application version, client city/country, hosting type, item count, error count, warning count, elapsed time.");
_logger.LogInformation(" -Exceptions: application errors and warnings.");
_logger.LogInformation(" -Dependencies: REST/ObjectModel calls to Azure DevOps to help us understand performance issues.");
_logger.LogInformation(" This data is tied to a session ID that is generated on each run of the application and shown in the logs. This can help with debugging. If you want to disable telemetry you can run the tool with '--disableTelemetry' on the command prompt.");
_logger.LogInformation(" Note: Exception data cannot be 100% guaranteed to not leak production data");
}

_logger.LogInformation("--------------------------------------");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ internal class ExecuteMigrationCommand : CommandBase<ExecuteMigrationCommandSett
private readonly IHostApplicationLifetime _appLifetime;
private readonly ITelemetryLogger Telemetery;


public ExecuteMigrationCommand(IServiceProvider services,
ILogger<ExecuteMigrationCommand> logger,
IHostApplicationLifetime appLifetime, ITelemetryLogger telemetryLogger, IDetectOnlineService detectOnlineService, IDetectVersionService2 detectVersionService, IMigrationToolVersion migrationToolVersion) : base(appLifetime, detectOnlineService, detectVersionService, logger, telemetryLogger, migrationToolVersion)
IHostApplicationLifetime appLifetime, ITelemetryLogger telemetryLogger, IDetectOnlineService detectOnlineService, IDetectVersionService2 detectVersionService, IMigrationToolVersion migrationToolVersion) : base(appLifetime, services, detectOnlineService, detectVersionService, logger, telemetryLogger, migrationToolVersion)
{
Telemetery = telemetryLogger;
_services = services;
Expand Down
21 changes: 4 additions & 17 deletions src/MigrationTools.Host/MigrationToolHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ public static IHostBuilder CreateDefaultBuilder(string[] args)
.Enrich.WithProcessId()
.WriteTo.File(logPath, LogEventLevel.Verbose, outputTemplate)
.WriteTo.Logger(lc => lc
.Filter.ByExcluding(Matching.FromSource("Microsoft"))
.Filter.ByExcluding(Matching.FromSource("MigrationTools.Host.StartupService"))
.Filter.ByExcluding(Matching.FromSource("Microsoft.Hosting.Lifetime"))
.Filter.ByExcluding(Matching.FromSource("Microsoft.Extensions.Hosting.Internal.Host"))
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Debug, theme: AnsiConsoleTheme.Code, outputTemplate: outputTemplate))
.WriteTo.Logger(lc => lc
.Filter.ByExcluding(Matching.FromSource("Microsoft"))
.WriteTo.ApplicationInsights(services.GetService<TelemetryConfiguration> (), new CustomConverter(), LogEventLevel.Error));
logs++;
LoggerHasBeenBuilt = true;
Expand All @@ -89,8 +88,8 @@ public static IHostBuilder CreateDefaultBuilder(string[] args)
var logger = sp.GetService<ILoggerFactory>().CreateLogger<EngineConfiguration>();
if (!File.Exists(configFile))
{
logger.LogInformation("The config file {ConfigFile} does not exist, nor does the default 'configuration.json'. Use '{ExecutableName}.exe init' to create a configuration file first", configFile, Assembly.GetEntryAssembly().GetName().Name);
throw new ArgumentException("missing configfile");
logger.LogCritical("The config file {ConfigFile} does not exist, nor does the default 'configuration.json'. Use '{ExecutableName}.exe init' to create a configuration file first", configFile, Assembly.GetEntryAssembly().GetName().Name);
Environment.Exit(-1);
}
logger.LogInformation("Config Found, creating engine host");
var reader = sp.GetRequiredService<IEngineConfigurationReader>();
Expand Down Expand Up @@ -175,18 +174,6 @@ public static async Task RunMigrationTools(this IHostBuilder hostBuilder, string
{
return;
}


// Disanle telemitery from options
//bool DisableTelemetry = false;
//Serilog.ILogger logger = host.Services.GetService<Serilog.ILogger>();
//if (executeOptions is not null && bool.TryParse(executeOptions.DisableTelemetry, out DisableTelemetry))
//{
// TelemetryConfiguration ai = host.Services.GetService<TelemetryConfiguration>();
// ai.DisableTelemetry = DisableTelemetry;
//}
//logger.Information("Telemetry: {status}", !DisableTelemetry);

await host.RunAsync();
}

Expand Down
17 changes: 15 additions & 2 deletions src/MigrationTools.Host/StartupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ public void RunStartupLogic(string[] args)

public void Configure(IHostApplicationLifetime appLifetime)
{

appLifetime.ApplicationStarted.Register(() =>
{
_logger.LogInformation("Press Ctrl+C to shut down.");
//_logger.LogInformation("Press Ctrl+C to shut down.");
});


appLifetime.ApplicationStopping.Register(() =>
{
//_logger.LogInformation("Stopping");
});


appLifetime.ApplicationStopped.Register(() =>
{
Expand All @@ -59,14 +67,18 @@ public void Configure(IHostApplicationLifetime appLifetime)

public void RunExitLogic()
{
if (Environment.ExitCode <0 )
{
_logger.LogError("The application ended with an error code of {ExitCode}", Environment.ExitCode);
}
_logger.LogTrace("Application Ending");
_mainTimer.Stop();
_telemetryLogger.TrackEvent("ApplicationEnd", null,
new Dictionary<string, double> {
{ "Application_Elapsed", _mainTimer.ElapsedMilliseconds }
});
_telemetryLogger.CloseAndFlush();
_logger.LogInformation("The application ran in {Application_Elapsed} and finished at {Application_EndTime}", _mainTimer.Elapsed.ToString("c"), DateTime.Now.ToUniversalTime().ToLocalTime());
_logger.LogDebug("The application ran in {Application_Elapsed} and finished at {Application_EndTime}", _mainTimer.Elapsed.ToString("c"), DateTime.Now.ToUniversalTime().ToLocalTime());
}

private void ApplicationStartup(string[] args)
Expand All @@ -79,6 +91,7 @@ private void ApplicationStartup(string[] args)
protected void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
_logger.LogError((Exception)e.ExceptionObject, "An Unhandled exception occured.");
_telemetryLogger.TrackException((Exception)e.ExceptionObject);
//_logger.LogCloseAndFlush();
System.Threading.Thread.Sleep(5000);
}
Expand Down
Loading