added logger to WPF UI

main
Jonas Arnold 4 years ago
parent bd3808fd23
commit f7720ffc67
  1. 28
      ADIS_Csharp/RobotClientWpf/MainWindow.xaml
  2. 7
      ADIS_Csharp/RobotClientWpf/MainWindow.xaml.cs
  3. 35
      ADIS_Csharp/RobotClientWpf/NLog.config
  4. 10
      ADIS_Csharp/RobotClientWpf/RobotClientWpf.csproj

@ -5,12 +5,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RobotClientWpf" xmlns:local="clr-namespace:RobotClientWpf"
xmlns:views="clr-namespace:RobotClientWpf.Views" xmlns:views="clr-namespace:RobotClientWpf.Views"
xmlns:dj="clr-namespace:DJ;assembly=NLogViewer"
mc:Ignorable="d" FontSize="15" mc:Ignorable="d" FontSize="15"
Title="Challenge UI" Height="700" Width="1200" WindowStartupLocation="CenterScreen" ResizeMode="NoResize"> Title="Challenge UI" Height="700" Width="1200" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="40"/> <RowDefinition Height="40"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="150"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
@ -46,7 +48,31 @@
</TabItem> </TabItem>
</TabControl> </TabControl>
<StackPanel Grid.Row="2" Orientation="Horizontal"> <dj:NLogViewer Grid.Row="2" Margin="10 0 10 0" DebugForeground="Black" MaxCount="150" ErrorForeground="Black" FatalForeground="Black" TraceForeground="Black" InfoForeground="Black" WarnForeground="Black">
<dj:NLogViewer.WarnBackground>
<SolidColorBrush Color="#FFFF9D00" Opacity="0.5"/>
</dj:NLogViewer.WarnBackground>
<dj:NLogViewer.TraceBackground>
<SolidColorBrush Color="#FF9B9B9B" Opacity="0.5"/>
</dj:NLogViewer.TraceBackground>
<dj:NLogViewer.InfoBackground>
<SolidColorBrush Color="#FF9B9B9B" Opacity="0.5"/>
</dj:NLogViewer.InfoBackground>
<dj:NLogViewer.DebugBackground>
<SolidColorBrush Color="#FF003DC3" Opacity="0.5"/>
</dj:NLogViewer.DebugBackground>
<dj:NLogViewer.ErrorBackground>
<SolidColorBrush Color="#FFFF2E00" Opacity="0.5"/>
</dj:NLogViewer.ErrorBackground>
<dj:NLogViewer.FatalBackground>
<SolidColorBrush Color="Red" Opacity="0.5"/>
</dj:NLogViewer.FatalBackground>
</dj:NLogViewer>
<!--<RichTextBox x:Name="rtbLogs" Grid.Row="2" Margin="10 0 10 0" IsReadOnly="True">
</RichTextBox>-->
<StackPanel Grid.Row="3" Orientation="Horizontal">
<TextBlock x:Name="tbBottomMessage" FontSize="15" Margin="10 5"/> <TextBlock x:Name="tbBottomMessage" FontSize="15" Margin="10 5"/>
</StackPanel> </StackPanel>
</Grid> </Grid>

@ -13,6 +13,7 @@ namespace RobotClientWpf
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
private ChallengeFactory challenge; private ChallengeFactory challenge;
private bool manualDisconnect; private bool manualDisconnect;
@ -27,7 +28,11 @@ namespace RobotClientWpf
{ {
if(e == false) if(e == false)
{ {
if (manualDisconnect == true) manualDisconnect = false; return; if (manualDisconnect == true)
{
manualDisconnect = false;
return;
}
this.DisplayBottomMessage(MessageSeverity.Error, "Connection to MQTT broker lost."); this.DisplayBottomMessage(MessageSeverity.Error, "Connection to MQTT broker lost.");
this.SetIpFieldsState(true, true, "Connect"); this.SetIpFieldsState(true, true, "Connect");
} }

@ -1,27 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
internalLogFile="c:\nlog-internal.txt" internalLogLevel="Trace">
<extensions>
<add assembly="NLogViewer"/>
</extensions>
<targets> <targets async="true">
<target xsi:type="RichTextBox" <target
name="String" xsi:type="CacheTarget"
layout="Layout" name="cache"/>
height="Integer"
autoScroll="Boolean"
maxLines="Integer"
showMinimized="Boolean"
toolWindow="Boolean"
controlName="String"
formName="String"
width="Integer"
useDefaultRowColoringRules="Boolean">
<word-coloring backgroundColor="String" fontColor="String" ignoreCase="Boolean"
regex="String" style="Enum" text="String"
wholeWords="Boolean"/>
<!-- repeated -->
<row-coloring backgroundColor="String" condition="Condition" fontColor="String"
style="Enum"/>
<!-- repeated -->
</target>
</targets> </targets>
<rules>
<logger name="*" writeTo="cache" minlevel="Debug"/>
</rules>
</nlog> </nlog>

@ -12,6 +12,10 @@
<None Remove="Assets\robot-industrial.png" /> <None Remove="Assets\robot-industrial.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Sentinel.NLogViewer" Version="2.0.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\RobotLib\RobotLib.csproj" /> <ProjectReference Include="..\RobotLib\RobotLib.csproj" />
</ItemGroup> </ItemGroup>
@ -25,4 +29,10 @@
</Resource> </Resource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

Loading…
Cancel
Save