Working with warnings
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Light"/>
|
||||
<FluentTheme/>
|
||||
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@@ -1,23 +1,23 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Data.Core;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using AvaloniaLoggingDI.ViewModels;
|
||||
using AvaloniaLoggingDI.Views;
|
||||
using LogViewer.Avalonia;
|
||||
using MessageBox.Avalonia;
|
||||
using MessageBox.Avalonia.Enums;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using MsLogger.Core;
|
||||
using RandomLogging.Service;
|
||||
using Icon = MessageBox.Avalonia.Enums.Icon;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Icon = MsBox.Avalonia.Enums.Icon;
|
||||
|
||||
namespace AvaloniaLoggingDI;
|
||||
|
||||
@@ -30,9 +30,9 @@ public partial class App : Application
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
// Line below is needed to remove Avalonia data validation.
|
||||
// Without this line you will get duplicate validations from both Avalonia and CT
|
||||
ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin);
|
||||
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
||||
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
|
||||
// catch all unhandled errors
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
@@ -94,7 +94,7 @@ public partial class App : Application
|
||||
|
||||
_host = builder.Build();
|
||||
_cancellationTokenSource = new();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
LogStartingMode();
|
||||
@@ -119,7 +119,17 @@ public partial class App : Application
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
private static void DisableAvaloniaDataAnnotationValidation()
|
||||
{
|
||||
// Get an array of plugins to remove
|
||||
var dataValidationPluginsToRemove = BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
||||
|
||||
// remove each entry found
|
||||
foreach (var plugin in dataValidationPluginsToRemove)
|
||||
{
|
||||
BindingPlugins.DataValidators.Remove(plugin);
|
||||
}
|
||||
}
|
||||
private void OnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
|
||||
=> _ = _host!.StopAsync(_cancellationTokenSource!.Token);
|
||||
|
||||
@@ -133,24 +143,27 @@ public partial class App : Application
|
||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
=> ShowMessageBox("Unhandled Error", ((Exception)e.ExceptionObject).Message);
|
||||
|
||||
private void ShowMessageBox(string title, string message)
|
||||
private static void ShowMessageBox(string title, string message)
|
||||
{
|
||||
MessageBox.Avalonia.BaseWindows.Base.IMsBoxWindow<ButtonResult> messageBoxStandardWindow = MessageBoxManager
|
||||
.GetMessageBoxStandardWindow(title, message, ButtonEnum.Ok, Icon.Stop);
|
||||
|
||||
messageBoxStandardWindow.Show();
|
||||
}
|
||||
var box = MessageBoxManager.GetMessageBoxStandard(
|
||||
"Exception",
|
||||
text: message,
|
||||
ButtonEnum.Ok,
|
||||
Icon.Stop
|
||||
);
|
||||
_ = box.ShowAsync().GetAwaiter();
|
||||
}
|
||||
|
||||
private void LogStartingMode()
|
||||
{
|
||||
// Get the Launch mode
|
||||
bool isDevelopment = string.Equals(Environment.GetEnvironmentVariable("DOTNET_MODIFIABLE_ASSEMBLIES"), "debug",
|
||||
StringComparison.InvariantCultureIgnoreCase);
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// initialize a logger & EventId
|
||||
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
|
||||
logger.TestPattern(eventId: eventId);
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
@@ -31,4 +34,8 @@
|
||||
<ProjectReference Include="..\..\Core\MsLogger.Core\MsLogger.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -2,15 +2,24 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using AvaloniaLoggingDI.ViewModels;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace AvaloniaLoggingDI;
|
||||
|
||||
// <summary>
|
||||
/// Given a view model, returns the corresponding view if possible.
|
||||
/// </summary>
|
||||
[RequiresUnreferencedCode(
|
||||
"Default implementation of ViewLocator involves reflection which may be trimmed away.",
|
||||
Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")]
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public IControl Build(object data)
|
||||
public Control? Build(object? param)
|
||||
{
|
||||
string name = data.GetType().FullName!.Replace("ViewModel", "View");
|
||||
Type? type = Type.GetType(name);
|
||||
if (param is null)
|
||||
return null;
|
||||
|
||||
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
||||
var type = Type.GetType(name);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
@@ -20,8 +29,8 @@ public class ViewLocator : IDataTemplate
|
||||
return new TextBlock { Text = "Not Found: " + name };
|
||||
}
|
||||
|
||||
public bool Match(object data)
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return data is ViewModelBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
|
||||
Title="C# AVALONIA | LogViewer Control Example - Dot Net 7.0"
|
||||
Icon="avares://Avalonia.Resources/Assets/avalonia-logo.ico"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
WindowStartupLocation="CenterScreen" Height="634" Width="600">
|
||||
|
||||
<control:LogViewerControl DataContext="{Binding LogViewer}" />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Light"/>
|
||||
<FluentTheme/>
|
||||
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@@ -4,6 +4,7 @@ using Avalonia.Data.Core;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using AvaloniaLoggingNoDI.Views;
|
||||
using System.Linq;
|
||||
|
||||
namespace AvaloniaLoggingNoDI;
|
||||
|
||||
@@ -18,12 +19,24 @@ public partial class App : Application
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
// Line below is needed to remove Avalonia data validation.
|
||||
// Without this line you will get duplicate validations from both Avalonia and CT
|
||||
ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin);
|
||||
desktop.MainWindow = new MainWindow();
|
||||
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
||||
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
desktop.MainWindow = new MainWindow();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
private static void DisableAvaloniaDataAnnotationValidation()
|
||||
{
|
||||
// Get an array of plugins to remove
|
||||
var dataValidationPluginsToRemove =
|
||||
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
||||
|
||||
// remove each entry found
|
||||
foreach (var plugin in dataValidationPluginsToRemove)
|
||||
{
|
||||
BindingPlugins.DataValidators.Remove(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,14 @@
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
|
||||
Title="C# AVALONIA MINIMAL | LogViewer Control Example - Dot Net 7.0"
|
||||
Icon="avares://Avalonia.Resources/Assets/avalonia-logo.ico"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
WindowStartupLocation="CenterScreen" Height="634" Width="600">
|
||||
|
||||
<control:LogViewerControl x:Name="LogViewerControl" />
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Light"/>
|
||||
<FluentTheme />
|
||||
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@@ -1,6 +1,5 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Data.Core;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using AvaloniaSerilogDI.ViewModels;
|
||||
@@ -8,28 +7,28 @@ using AvaloniaSerilogDI.Views;
|
||||
using Common.Core.Extensions;
|
||||
using LogViewer.Avalonia;
|
||||
using LogViewer.Core;
|
||||
using MessageBox.Avalonia;
|
||||
using MessageBox.Avalonia.Enums;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using RandomLogging.Service;
|
||||
using Serilog;
|
||||
using Serilog.Sinks.LogView.Core;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Icon = MessageBox.Avalonia.Enums.Icon;
|
||||
|
||||
using Icon = MsBox.Avalonia.Enums.Icon;
|
||||
namespace AvaloniaSerilogDI;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
=> AvaloniaXamlLoader.Load(this);
|
||||
=> AvaloniaXamlLoader.Load(this);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -42,91 +41,58 @@ public partial class App : Application
|
||||
|
||||
#region Methods
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
// Line below is needed to remove Avalonia data validation.
|
||||
// Without this line you will get duplicate validations from both Avalonia and CT
|
||||
ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin);
|
||||
|
||||
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
||||
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
// catch all unhandled errors
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
|
||||
HostApplicationBuilder builder = Host.CreateApplicationBuilder();
|
||||
|
||||
builder
|
||||
// Register the Random Logging Service
|
||||
.AddRandomBackgroundService()
|
||||
builder
|
||||
// Register the Random Logging Service
|
||||
.AddRandomBackgroundService()
|
||||
|
||||
// visual debugging tools
|
||||
.AddLogViewer();
|
||||
// visual debugging tools
|
||||
.AddLogViewer();
|
||||
|
||||
IServiceCollection services = builder.Services;
|
||||
IServiceCollection services = builder.Services;
|
||||
|
||||
// Serilog Logger
|
||||
// Serilog Logger
|
||||
|
||||
// Azure: https://devblogs.microsoft.com/dotnet/asp-net-core-logging/
|
||||
// ApplicationInsights: https://github.com/serilog-contrib/serilog-sinks-applicationinsights
|
||||
// AmazonCloudWatch: https://blog.ivankahl.com/logging-dotnet-to-aws-cloudwatch-using-serilog/
|
||||
// video: https://www.youtube.com/watch?v=nVAkSBpsuTk (How Structured Logging With Serilog Can Make Your Life Easier)
|
||||
// video: https://www.youtube.com/watch?v=_iryZxv8Rxw (C# Logging with Serilog and Seq - Structured Logging Made Easy)
|
||||
// ps: docker run -d --restart unless-stopped --name seq -e ACCEPT_EULA=Y -v c:\WIP\LogData:/data -p 8081:80 datalust/seq:latest
|
||||
// docker rmi datalust/seq --force
|
||||
// Azure: https://devblogs.microsoft.com/dotnet/asp-net-core-logging/
|
||||
// ApplicationInsights: https://github.com/serilog-contrib/serilog-sinks-applicationinsights
|
||||
// AmazonCloudWatch: https://blog.ivankahl.com/logging-dotnet-to-aws-cloudwatch-using-serilog/
|
||||
// video: https://www.youtube.com/watch?v=nVAkSBpsuTk (How Structured Logging With Serilog Can Make Your Life Easier)
|
||||
// video: https://www.youtube.com/watch?v=_iryZxv8Rxw (C# Logging with Serilog and Seq - Structured Logging Made Easy)
|
||||
// ps: docker run -d --restart unless-stopped --name seq -e ACCEPT_EULA=Y -v c:\WIP\LogData:/data -p 8081:80 datalust/seq:latest
|
||||
// docker rmi datalust/seq --force
|
||||
|
||||
// ref: https://stackoverflow.com/questions/66304596/how-to-dependency-inject-serilog-into-the-rest-of-my-classes-in-net-console-app
|
||||
services.AddLogging(configure: cfg =>
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
//Serilog.Core.Logger logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.WriteTo.DataStoreLoggerSink(
|
||||
dataStoreProvider: () => _host!.Services.TryGetService<ILogDataStore>()!
|
||||
|
||||
//dataStoreProvider: () => _host!.Services.TryGetService<ILogDataStore>()!,
|
||||
//options =>
|
||||
//{
|
||||
// options.Colors[LogLevel.Trace] = new()
|
||||
// {
|
||||
// Foreground = Color.White,
|
||||
// Background = Color.DarkGray
|
||||
// };
|
||||
|
||||
// options.Colors[LogLevel.Debug] = new()
|
||||
// {
|
||||
// Foreground = Color.White,
|
||||
// Background = Color.Gray
|
||||
// };
|
||||
|
||||
// options.Colors[LogLevel.Information] = new()
|
||||
// {
|
||||
// Foreground = Color.White,
|
||||
// Background = Color.DodgerBlue
|
||||
// };
|
||||
|
||||
// options.Colors[LogLevel.Warning] = new()
|
||||
// {
|
||||
// Foreground = Color.White,
|
||||
// Background = Color.Orchid
|
||||
// };
|
||||
//}
|
||||
)
|
||||
.CreateLogger();
|
||||
|
||||
cfg.ClearProviders()
|
||||
.AddSerilog(Log.Logger);
|
||||
});
|
||||
|
||||
services
|
||||
.AddSingleton<MainViewModel>()
|
||||
.AddSingleton(service => new MainWindow
|
||||
// ref: https://stackoverflow.com/questions/66304596/how-to-dependency-inject-serilog-into-the-rest-of-my-classes-in-net-console-app
|
||||
services.AddLogging(configure: cfg =>
|
||||
{
|
||||
DataContext = service.GetRequiredService<MainViewModel>()
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.WriteTo.DataStoreLoggerSink( dataStoreProvider: () => _host!.Services.TryGetService<ILogDataStore>()!,formatProvider: CultureInfo.InvariantCulture)
|
||||
.CreateLogger();
|
||||
|
||||
cfg.ClearProviders().AddSerilog(Log.Logger);
|
||||
});
|
||||
|
||||
services
|
||||
.AddSingleton<MainViewModel>()
|
||||
.AddSingleton(service => new MainWindow
|
||||
{
|
||||
DataContext = service.GetRequiredService<MainViewModel>()
|
||||
});
|
||||
|
||||
_host = builder.Build();
|
||||
_cancellationTokenSource = new();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
LogStartingMode();
|
||||
@@ -155,8 +121,18 @@ public partial class App : Application
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
private static void DisableAvaloniaDataAnnotationValidation()
|
||||
{
|
||||
// Get an array of plugins to remove
|
||||
var dataValidationPluginsToRemove = BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
||||
|
||||
private void OnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
|
||||
// remove each entry found
|
||||
foreach (var plugin in dataValidationPluginsToRemove)
|
||||
{
|
||||
BindingPlugins.DataValidators.Remove(plugin);
|
||||
}
|
||||
}
|
||||
private void OnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
|
||||
=> CleanUp();
|
||||
|
||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
@@ -169,23 +145,25 @@ public partial class App : Application
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
private void ShowMessageBox(string title, string message)
|
||||
private static void ShowMessageBox(string title, string message)
|
||||
{
|
||||
MessageBox.Avalonia.BaseWindows.Base.IMsBoxWindow<ButtonResult> messageBoxStandardWindow = MessageBoxManager
|
||||
.GetMessageBoxStandardWindow(title, message, ButtonEnum.Ok, Icon.Stop);
|
||||
|
||||
messageBoxStandardWindow.Show();
|
||||
var box = MessageBoxManager.GetMessageBoxStandard(
|
||||
"Exception",
|
||||
text: message,
|
||||
ButtonEnum.Ok,
|
||||
Icon.Stop
|
||||
);
|
||||
_ = box.ShowAsync().GetAwaiter();
|
||||
}
|
||||
|
||||
private void LogStartingMode()
|
||||
{
|
||||
// Get the Launch mode
|
||||
bool isDevelopment = string.Equals(Environment.GetEnvironmentVariable("DOTNET_MODIFIABLE_ASSEMBLIES"), "debug",
|
||||
StringComparison.InvariantCultureIgnoreCase);
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// initialize a logger & EventId
|
||||
ILogger<App> logger = _host!.Services.GetRequiredService<ILogger<App>>();
|
||||
EventId eventId = new EventId(id: 0, name: Assembly.GetEntryAssembly()!.GetName().Name);
|
||||
EventId eventId = new(id: 0, name: Assembly.GetEntryAssembly()!.GetName().Name);
|
||||
|
||||
// log a test pattern for each log level
|
||||
logger.TestPattern(eventId: eventId);
|
||||
@@ -197,7 +175,7 @@ public partial class App : Application
|
||||
private void CleanUp()
|
||||
{
|
||||
// tell the background services that we are shutting down
|
||||
_ = _host!.StopAsync(_cancellationTokenSource!.Token);
|
||||
_ = _host?.StopAsync(_cancellationTokenSource?.Token ?? CancellationToken.None);
|
||||
|
||||
// flush logs
|
||||
Log.CloseAndFlush();
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
|
||||
@@ -2,15 +2,24 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using AvaloniaSerilogDI.ViewModels;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace AvaloniaSerilogDI;
|
||||
|
||||
// <summary>
|
||||
/// Given a view model, returns the corresponding view if possible.
|
||||
/// </summary>
|
||||
[RequiresUnreferencedCode(
|
||||
"Default implementation of ViewLocator involves reflection which may be trimmed away.",
|
||||
Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")]
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public IControl Build(object data)
|
||||
public Control? Build(object? param)
|
||||
{
|
||||
string name = data.GetType().FullName!.Replace("ViewModel", "View");
|
||||
Type? type = Type.GetType(name);
|
||||
if (param is null)
|
||||
return null;
|
||||
|
||||
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
||||
var type = Type.GetType(name);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
@@ -20,8 +29,8 @@ public class ViewLocator : IDataTemplate
|
||||
return new TextBlock { Text = "Not Found: " + name };
|
||||
}
|
||||
|
||||
public bool Match(object data)
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return data is ViewModelBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
|
||||
Title="C# AVALONIA SeriLog | LogViewer Control Example - Dot Net 7.0"
|
||||
Icon="avares://Avalonia.Resources/Assets/avalonia-logo.ico"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
WindowStartupLocation="CenterScreen" Height="634" Width="600">
|
||||
|
||||
<control:LogViewerControl DataContext="{Binding LogViewer}" />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
x:Class="AvaloniaSerilogNoDI.App">
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Light"/>
|
||||
<FluentTheme/>
|
||||
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@@ -4,6 +4,12 @@
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Sinks.LogView.Core;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AvaloniaSerilogNoDI.Helpers;
|
||||
|
||||
@@ -21,10 +22,7 @@ public static class LoggingHelper
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.WriteTo.DataStoreLoggerSink(
|
||||
//dataStoreProvider: () => MainControlsDataStore.DataStore
|
||||
|
||||
dataStoreProvider: () => MainControlsDataStore.DataStore,
|
||||
.WriteTo.DataStoreLoggerSink(dataStoreProvider: () => MainControlsDataStore.DataStore,
|
||||
options =>
|
||||
{
|
||||
options.Colors[LogLevel.Trace] = new()
|
||||
@@ -50,7 +48,7 @@ public static class LoggingHelper
|
||||
Foreground = Color.White,
|
||||
Background = Color.Orchid
|
||||
};
|
||||
}
|
||||
}, formatProvider: CultureInfo.InvariantCulture
|
||||
)
|
||||
.CreateLogger();
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
xmlns:control="clr-namespace:LogViewer.Avalonia;assembly=LogViewer.Avalonia"
|
||||
|
||||
Title="C# AVALONIA | SeriLog LogViewer Control Example - Dot Net 7.0"
|
||||
Icon="avares://Avalonia.Resources/Assets/avalonia-logo.ico"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
WindowStartupLocation="CenterScreen" Height="634" Width="600">
|
||||
|
||||
<control:LogViewerControl x:Name="LogViewerControl" />
|
||||
|
||||
Reference in New Issue
Block a user