Fixed Warnings
This commit is contained in:
@@ -37,7 +37,7 @@ public partial class App : Application
|
||||
// catch all unhandled errors
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
|
||||
HostApplicationBuilder builder = Host.CreateApplicationBuilder();
|
||||
HostApplicationBuilder builder = Microsoft.Extensions.Hosting.Host.CreateApplicationBuilder();
|
||||
|
||||
builder
|
||||
/*
|
||||
@@ -87,24 +87,24 @@ public partial class App : Application
|
||||
|
||||
services
|
||||
.AddSingleton<MainViewModel>()
|
||||
.AddSingleton<MainWindow>(service => new MainWindow
|
||||
.AddSingleton(service => new MainWindow
|
||||
{
|
||||
DataContext = service.GetRequiredService<MainViewModel>()
|
||||
});
|
||||
|
||||
_host = builder.Build();
|
||||
_cancellationTokenSource = new();
|
||||
Host = builder.Build();
|
||||
CancellationTokenSource = new();
|
||||
|
||||
try
|
||||
{
|
||||
LogStartingMode();
|
||||
|
||||
// set and show
|
||||
desktop.MainWindow = _host.Services.GetRequiredService<MainWindow>();
|
||||
desktop.MainWindow = Host.Services.GetRequiredService<MainWindow>();
|
||||
desktop.ShutdownRequested += OnShutdownRequested;
|
||||
|
||||
// startup background services
|
||||
_ = _host.StartAsync(_cancellationTokenSource.Token);
|
||||
_ = Host.StartAsync(CancellationTokenSource.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -131,15 +131,13 @@ public partial class App : Application
|
||||
}
|
||||
}
|
||||
private void OnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
|
||||
=> _ = _host!.StopAsync(_cancellationTokenSource!.Token);
|
||||
=> _ = Host?.StopAsync(CancellationTokenSource!.Token);
|
||||
|
||||
#region Fields
|
||||
|
||||
private IHost? _host;
|
||||
private CancellationTokenSource? _cancellationTokenSource;
|
||||
|
||||
#endregion
|
||||
|
||||
private IHost? Host { get; set; }
|
||||
private CancellationTokenSource? CancellationTokenSource { get; set; }
|
||||
|
||||
|
||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
=> ShowMessageBox("Unhandled Error", ((Exception)e.ExceptionObject).Message);
|
||||
|
||||
@@ -161,7 +159,7 @@ public partial class App : Application
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// initialize a logger & EventId
|
||||
ILogger<App> logger = _host!.Services.GetRequiredService<ILogger<App>>();
|
||||
ILogger<App> logger = Host!.Services.GetRequiredService<ILogger<App>>();
|
||||
EventId eventId = new EventId(id: 0, name: Assembly.GetEntryAssembly()!.GetName().Name);
|
||||
|
||||
// log a test pattern for each log level
|
||||
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
|
||||
namespace AvaloniaLoggingDI;
|
||||
|
||||
internal class Program
|
||||
internal sealed class Program
|
||||
{
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
|
||||
Title="C# AVALONIA | LogViewer Control Example - Dot Net 7.0"
|
||||
Title="AvaloniaLoggingDI-MsLogger"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
WindowStartupLocation="CenterScreen" Height="634" Width="600">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user