mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-09-16 05:19:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26da84c4e7 | ||
|
|
a39e8dc5c6 |
@@ -10,6 +10,8 @@ namespace Daybreak.Tests.Models
|
||||
[TestClass]
|
||||
public class VersionTests
|
||||
{
|
||||
[DataRow("v0.1.0.0.1", "v0.1.0.0.1")]
|
||||
[DataRow("v0.1.0.0.1.0.0.0.0", "v0.1.0.0.1")]
|
||||
[DataRow("v0.1.0", "v0.1")]
|
||||
[DataRow("0.1.0", "0.1")]
|
||||
[DataRow("v0.1.0.0.0", "v0.1")]
|
||||
|
||||
@@ -4,6 +4,7 @@ using LiteDB;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.IO;
|
||||
using WpfExtended.Logging;
|
||||
|
||||
namespace Daybreak.Tests.Services
|
||||
{
|
||||
@@ -20,7 +21,7 @@ namespace Daybreak.Tests.Services
|
||||
File.Delete("Daybreak.db");
|
||||
this.liteDatabase = new LiteDatabase("Daybreak.db");
|
||||
this.logsManager = new JsonLogsManager(this.liteDatabase);
|
||||
this.loggerProvider = new JsonLoggerProvider(this.logsManager);
|
||||
this.loggerProvider = new CVLoggerProvider(this.logsManager);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -22,7 +22,7 @@ using System.Extensions;
|
||||
using System.Net.Http;
|
||||
using System.Windows.Extensions.Http;
|
||||
using LiteDB;
|
||||
using Daybreak.Controls;
|
||||
using System.Windows.Extensions;
|
||||
|
||||
namespace Daybreak.Configuration
|
||||
{
|
||||
@@ -32,7 +32,6 @@ namespace Daybreak.Configuration
|
||||
{
|
||||
serviceManager.ThrowIfNull(nameof(serviceManager));
|
||||
|
||||
serviceManager.RegisterScoped<ILoggerFactory, CVLoggerFactory>((sp) => new CVLoggerFactory(sp.GetService<ILogsManager>()));
|
||||
serviceManager.RegisterResolver(
|
||||
new HttpClientResolver()
|
||||
.WithHttpMessageHandlerFactory((serviceProvider, categoryType) =>
|
||||
@@ -64,7 +63,7 @@ namespace Daybreak.Configuration
|
||||
serviceProducer.RegisterScoped<IIconRetriever, IconRetriever>();
|
||||
serviceProducer.RegisterScoped<IPrivilegeManager, PrivilegeManager>();
|
||||
serviceProducer.RegisterScoped<IScreenManager, ScreenManager>();
|
||||
serviceProducer.RegisterScoped<ILogsManager, JsonLogsManager>();
|
||||
serviceProducer.RegisterLogWriter<ILogsManager, JsonLogsManager>();
|
||||
}
|
||||
public static void RegisterLifetimeServices(IApplicationLifetimeProducer applicationLifetimeProducer)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<LangVersion>preview</LangVersion>
|
||||
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
|
||||
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
|
||||
<Version>0.9</Version>
|
||||
<Version>0.9.0.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -23,11 +23,11 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NReco.Logging.File" Version="1.1.1" />
|
||||
<PackageReference Include="securifybv.ShellLink" Version="0.1.0" />
|
||||
<PackageReference Include="Slim" Version="1.4.2" />
|
||||
<PackageReference Include="Slim" Version="1.4.3" />
|
||||
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
|
||||
<PackageReference Include="SystemExtensions.NetStandard" Version="1.2.0" />
|
||||
<PackageReference Include="SystemExtensions.NetStandard" Version="1.3.0" />
|
||||
<PackageReference Include="WCL" Version="1.0.2" />
|
||||
<PackageReference Include="WpfExtended" Version="0.3.3" />
|
||||
<PackageReference Include="WpfExtended" Version="0.4.1" />
|
||||
<PackageReference Include="WpfExtended.SourceGeneration" Version="0.1.1" />
|
||||
<PackageReference Include="WpfScreenHelper" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Models
|
||||
{
|
||||
public sealed class Log
|
||||
{
|
||||
[JsonProperty("DateTime")]
|
||||
public DateTime LogTime { get; set; }
|
||||
[JsonProperty("Category")]
|
||||
public string Category { get; set; }
|
||||
[JsonProperty("EventId")]
|
||||
public string EventId { get; set; }
|
||||
[JsonProperty("LogLevel")]
|
||||
public LogLevel LogLevel { get; set; }
|
||||
[JsonProperty("Message")]
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,10 @@ namespace Daybreak.Models.Versioning
|
||||
{
|
||||
parts.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
parsedVersion = new Version
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public sealed class CVLoggerFactory : ILoggerFactory
|
||||
{
|
||||
private readonly LoggerFactory loggerFactory = new();
|
||||
|
||||
public CVLoggerFactory(ILogsManager logsManager)
|
||||
{
|
||||
this.loggerFactory.AddProvider(new JsonLoggerProvider(logsManager));
|
||||
}
|
||||
|
||||
public void AddProvider(ILoggerProvider provider)
|
||||
{
|
||||
((ILoggerFactory)this.loggerFactory).AddProvider(provider);
|
||||
}
|
||||
|
||||
public ILogger CreateLogger(string categoryName)
|
||||
{
|
||||
return ((ILoggerFactory)this.loggerFactory).CreateLogger(categoryName);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
((IDisposable)this.loggerFactory).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
using Daybreak.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using WpfExtended.Logging;
|
||||
using WpfExtended.Models;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public interface ILogsManager
|
||||
public interface ILogsManager : ILogsWriter
|
||||
{
|
||||
void WriteLog(Log log);
|
||||
IEnumerable<Log> GetLogs();
|
||||
int DeleteLogs();
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
using Daybreak.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Extensions;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public sealed class JsonLogger : ILogger
|
||||
{
|
||||
private readonly string category;
|
||||
private readonly JsonLoggerProvider jsonLoggerProvider;
|
||||
|
||||
public JsonLogger(string category, JsonLoggerProvider jsonLoggerProvider)
|
||||
{
|
||||
this.category = category;
|
||||
this.jsonLoggerProvider = jsonLoggerProvider.ThrowIfNull(nameof(jsonLoggerProvider));
|
||||
}
|
||||
|
||||
public IDisposable BeginScope<TState>(TState state)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
{
|
||||
var message = formatter(state, exception);
|
||||
|
||||
var log = new Log
|
||||
{
|
||||
LogLevel = logLevel,
|
||||
EventId = eventId.Name,
|
||||
Message = message,
|
||||
Category = category,
|
||||
LogTime = DateTime.Now
|
||||
};
|
||||
|
||||
this.jsonLoggerProvider.LogEntry(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using Daybreak.Models;
|
||||
using Microsoft.CorrelationVector;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Extensions;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
public sealed class JsonLoggerProvider : ILoggerProvider
|
||||
{
|
||||
private readonly ILogsManager logsManager;
|
||||
private CorrelationVector correlationVector;
|
||||
|
||||
public JsonLoggerProvider(ILogsManager logsManager)
|
||||
{
|
||||
this.logsManager = logsManager.ThrowIfNull(nameof(logsManager));
|
||||
this.correlationVector = new CorrelationVector();
|
||||
}
|
||||
|
||||
public void LogEntry(Log log)
|
||||
{
|
||||
if (this.correlationVector is not null)
|
||||
{
|
||||
log.Message = $"[{this.correlationVector.Value}] {log.Message}";
|
||||
this.correlationVector.Increment();
|
||||
}
|
||||
|
||||
this.logsManager.WriteLog(log);
|
||||
}
|
||||
|
||||
public ILogger CreateLogger(string categoryName)
|
||||
{
|
||||
if (this.correlationVector is not null)
|
||||
{
|
||||
this.correlationVector = CorrelationVector.Extend(this.correlationVector.ToString());
|
||||
}
|
||||
|
||||
return new JsonLogger(categoryName, this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Daybreak.Models;
|
||||
using LiteDB;
|
||||
using LiteDB;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
using WpfExtended.Models;
|
||||
|
||||
namespace Daybreak.Services.Logging
|
||||
{
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="DateTime" Binding="{Binding LogTime}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="CV" Binding="{Binding CorrelationVector}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="Category" Binding="{Binding Category}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="LogLevel" Binding="{Binding LogLevel}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
<DataGridTextColumn IsReadOnly="True" Header="EventId" Binding="{Binding EventId}" ElementStyle="{StaticResource WrapText}" Width="auto"/>
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Extensions;
|
||||
using System.Windows.Controls;
|
||||
using Daybreak.Models;
|
||||
using WpfExtended.Models;
|
||||
|
||||
namespace Daybreak.Views
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user