change - 系统框架样式修改

master
wenjy 3 months ago
parent dbb4bfa80b
commit 9b3c1cd057

@ -1,5 +1,6 @@
using Autofac; using Autofac;
using SlnMesnac.Repository; using SlnMesnac.Repository;
using SlnMesnac.Serilog;
using System.Reflection; using System.Reflection;
using TouchSocket.Sockets; using TouchSocket.Sockets;
@ -60,6 +61,9 @@ namespace SlnMesnac.Ioc
//注入代码生成 //注入代码生成
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Generate.dll")); RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Generate.dll"));
//注入Serilog日志帮助类
builder.RegisterType(typeof(SerilogHelper)).SingleInstance();
} }

@ -45,12 +45,25 @@ namespace SlnMesnac.Serilog
var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/";
#endregion #endregion
//Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console()
// .WriteTo.File(Path.Combine(logPath, "Info.log"), LogEventLevel.Information)
// .WriteTo.File(Path.Combine(logPath, "Error.log"), LogEventLevel.Error)
// .WriteTo.File(Path.Combine(logPath, "Warn.log"), LogEventLevel.Warning)
// //.WriteTo.File(Path.Combine(logPath, "Debug.log"), LogEventLevel.Debug, fileSizeLimitBytes: 5 * 1024)
// .CreateLogger();
Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console()
.WriteTo.File(Path.Combine(logPath, "Info.log"), LogEventLevel.Information) .WriteTo.Logger(lc => lc
.WriteTo.File(Path.Combine(logPath, "Error.log"), LogEventLevel.Error) .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Info"))
.WriteTo.File(Path.Combine(logPath, "Warn.log"), LogEventLevel.Warning) .WriteTo.File(Path.Combine(logPath, "Info.log")))
//.WriteTo.File(Path.Combine(logPath, "Debug.log"), LogEventLevel.Debug, fileSizeLimitBytes: 5 * 1024) .WriteTo.Logger(lc => lc
.CreateLogger(); .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Plc"))
.WriteTo.File(Path.Combine(logPath, "Plc.log")))
.WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Error"))
.WriteTo.File(Path.Combine(logPath, "Error.log")))
.CreateLogger();
app.UseSerilogRequestLogging(); app.UseSerilogRequestLogging();
return app; return app;

@ -0,0 +1,95 @@
using Serilog;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* T14-GEN3-7895
* SlnMesnac.Serilog
* a537790e-bf7c-4dd6-ade7-fc8cd5bd6d0d
*
* WenJY
*
* 2024-10-12 10:42:44
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Serilog
{
/// <summary>
/// Serilog日志类
/// </summary>
public class SerilogHelper
{
private readonly ILogger? Info_logger = Log.ForContext("Module", "Info");
private readonly ILogger? Plc_logger = Log.ForContext("Module", "Plc");
private readonly ILogger? Error_logger = Log.ForContext("Module", "Error");
/// <summary>
/// Info日志
/// </summary>
/// <param name="msg"></param>
public void Info(string msg)
{
if(Info_logger!= null)
{
this.Info_logger.Information(msg);
}
}
/// <summary>
/// Plc日志
/// </summary>
/// <param name="msg"></param>
public void Plc(string msg)
{
if (Plc_logger != null)
{
this.Plc_logger.Information(msg);
}
}
/// <summary>
/// Error日志
/// </summary>
/// <param name="msg"></param>
/// <param name="ex"></param>
public void Error(string msg, Exception ex = null)
{
if (!string.IsNullOrEmpty(msg) && ex == null)
{
this.Error_logger.Information("【附加信息】 : {0}<br>", new object[] { msg });
}
else if (!string.IsNullOrEmpty(msg) && ex != null)
{
string errorMsg = BeautyErrorMsg(ex);
this.Error_logger.Information("【附加信息】 : {0}<br>{1}", new object[] { msg, errorMsg });
}
else if (string.IsNullOrEmpty(msg) && ex != null)
{
string errorMsg = BeautyErrorMsg(ex);
this.Error_logger.Information(errorMsg);
}
}
private string BeautyErrorMsg(Exception ex)
{
string errorMsg = string.Format("【异常类型】:{0} <br>【异常信息】:{1} <br>【堆栈调用】:{2}", new object[] { ex.GetType().Name, ex.Message, ex.StackTrace });
errorMsg = errorMsg.Replace("\r\n", "<br>");
errorMsg = errorMsg.Replace("位置", "<strong style=\"color:red\">位置</strong>");
return errorMsg;
}
}
}

@ -7,6 +7,7 @@ using SlnMesnac.Config;
using System; using System;
using System.Windows; using System.Windows;
using Autofac.Extensions.DependencyInjection; using Autofac.Extensions.DependencyInjection;
using SlnMesnac.Serilog;
namespace SlnMesnac.WPF namespace SlnMesnac.WPF
{ {
@ -18,6 +19,7 @@ namespace SlnMesnac.WPF
private System.Threading.Mutex? mutex = null; private System.Threading.Mutex? mutex = null;
private LierdaCracker cracker = new LierdaCracker(); private LierdaCracker cracker = new LierdaCracker();
public static IServiceProvider? ServiceProvider = null; public static IServiceProvider? ServiceProvider = null;
private SerilogHelper serilogHelper = null;
// Startup事件 // Startup事件
protected override async void OnStartup(StartupEventArgs e) protected override async void OnStartup(StartupEventArgs e)
@ -36,13 +38,12 @@ namespace SlnMesnac.WPF
var host = CreateHostBuilder(e.Args).Build();//生成宿主。 var host = CreateHostBuilder(e.Args).Build();//生成宿主。
ServiceProvider = host.Services; ServiceProvider = host.Services;
await host.StartAsync(); await host.StartAsync();
serilogHelper = ServiceProvider.GetService<SerilogHelper>();
var appConfig = host.Services.GetService<AppConfig>(); var appConfig = host.Services.GetService<AppConfig>();
var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/";
Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}"); serilogHelper.Info($"系统初始化完成,日志存放路径:{appConfig.logPath}");
} }
/// <summary> /// <summary>

@ -6,55 +6,27 @@
xmlns:local="clr-namespace:SlnMesnac.WPF" xmlns:local="clr-namespace:SlnMesnac.WPF"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="1080" Width="1920" Title="MainWindow" Height="1080" Width="1920"
WindowState="Maximized" WindowStyle="None" ResizeMode="NoResize" Topmost="False"> WindowState="Maximized" WindowStyle="None" ResizeMode="NoResize" Topmost="False" Background="#F4F5FA">
<Window.Background> <!--<Window.Background>
<ImageBrush ImageSource="/Templates/image/background.jpg" /> <ImageBrush ImageSource="/Templates/image/background.jpg" />
</Window.Background> </Window.Background>-->
<Border Margin="5" Background="Transparent" CornerRadius="10"> <Border Margin="5" Background="Transparent" CornerRadius="10">
<Border.Effect>
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"></DropShadowEffect>
</Border.Effect>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="0.5*"/> <RowDefinition Height="0.7*"/>
<RowDefinition Height="7*"/> <RowDefinition Height="7*"/>
<RowDefinition Height="0.7*"/> <RowDefinition Height="0.7*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="Red" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="2,2"> <Border Grid.Row="0" BorderBrush="Red" BorderThickness="0" CornerRadius="0" Background="#0050BF">
<Grid> <TextBlock Text="轨道巡检控制系统" FontSize="30" Foreground="White" FontWeight="Bold" Margin="50,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="生产控制系统" FontSize="50" Foreground="White" FontWeight="Bold"/>
</StackPanel>
<StackPanel Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="白班" FontSize="25" Foreground="White" FontWeight="Bold" Margin="0,0,30,0"/>
<TextBlock Grid.Column="1" Text="|" FontSize="25" Foreground="White" FontWeight="Bold" Margin="0,0,30,0"/>
<TextBlock Grid.Column="2" Text="SCADA" FontSize="25" Foreground="White" FontWeight="Bold" Margin="0,0,10,0"/>
</Grid>
</StackPanel>
</Grid>
</Border> </Border>
<Border Grid.Row="1" BorderBrush="Red" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="2,25,2,2"> <Border Grid.Row="1" BorderBrush="Red" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="2,25,2,2">
<ContentControl Content="{Binding UserContent}"/> <ContentControl Content="{Binding UserContent}"/>
</Border> </Border>
<Border Grid.Row="2" BorderBrush="#1254AB" BorderThickness="2" CornerRadius="5" Background="Transparent" Margin="6,2,6,7"> <Border Grid.Row="2" BorderBrush="#1254AB" BorderThickness="0" CornerRadius="5" Background="#FFFFFF" Margin="6,2,6,7">
<Border.Effect>
<DropShadowEffect Color="#1254AB" Direction="270" BlurRadius="10" ShadowDepth="5" Opacity="0.5"/>
</Border.Effect>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/> <ColumnDefinition Width="2*"/>
@ -68,9 +40,9 @@
<Button Content="退 出" x:Name="Exit" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=Exit}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0,10,0"/> <Button Content="退 出" x:Name="Exit" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=Exit}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0,10,0"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal"> <!--<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
<!--多行状态显示--> --><!--多行状态显示-->
<!--<Grid> <!--<Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
@ -155,7 +127,7 @@
</StackPanel> </StackPanel>
</Grid>--> </Grid>-->
<!--单行状态显示--> <!--单行状态显示--><!--
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@ -257,7 +229,7 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
</StackPanel> </StackPanel>-->
</Grid> </Grid>

@ -8,7 +8,7 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"AppConfig": { "AppConfig": {
"logPath": "E:\\桌面\\SlnMesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows", "logPath": "F:\\桌面\\赛轮智慧热电项目\\日志信息",
"SqlConfig": [ "SqlConfig": [
{ {
"configId": "mes", "configId": "mes",

Loading…
Cancel
Save