Skip to content

Commit e8561b3

Browse files
authored
Merge pull request #11 from itn3000/add-eventlog
add log filter options
2 parents ba757d2 + 888a7eb commit e8561b3

File tree

4 files changed

+164
-75
lines changed

4 files changed

+164
-75
lines changed

src/WEventViewer/MainWindow.axaml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
<DataGridTextColumn Header="TimeCreated" Binding="{Binding TimeCreated}"/>
4242
<DataGridTextColumn Header="LogName" Binding="{Binding LogName}"/>
43+
<DataGridTextColumn Header="Provider" Binding="{Binding ProviderName}"/>
4344
<DataGridTextColumn Header="Id" Binding="{Binding Id}"/>
4445
<DataGridTextColumn Header="Level" Binding="{Binding Level}"/>
4546
<DataGridTextColumn Header="Description" Binding="{Binding Formatted}"/>

src/WEventViewer/OpenLogWindow.axaml

+92-64
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,40 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:vm="using:WEventViewer.ViewModel"
66
xmlns:local="using:WEventViewer"
7-
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="500"
7+
mc:Ignorable="d" d:DesignWidth="700" d:DesignHeight="600"
88
x:Class="WEventViewer.OpenLogWindow"
99
x:DataType="vm:OpenLogWindowViewModel"
1010
Title="OpenLogWindow">
11-
<Design.DataContext>
12-
<vm:OpenLogWindowViewModel/>
13-
</Design.DataContext>
14-
<Window.Resources>
15-
<vm:PathTypeValueConverter x:Key="PathTypeConverter"/>
16-
</Window.Resources>
17-
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20">
18-
<Grid.RowDefinitions>
19-
<RowDefinition Height="*"></RowDefinition>
20-
<RowDefinition Height="Auto"></RowDefinition>
21-
</Grid.RowDefinitions>
22-
<StackPanel Margin="10" Orientation="Vertical" Grid.Row="0" Name="OptionPanel">
23-
<Grid HorizontalAlignment="Stretch" Grid.Row="0" VerticalAlignment="Center">
11+
<Design.DataContext>
12+
<vm:OpenLogWindowViewModel/>
13+
</Design.DataContext>
14+
<Window.Resources>
15+
<vm:PathTypeValueConverter x:Key="PathTypeConverter"/>
16+
</Window.Resources>
17+
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20">
18+
<Grid.RowDefinitions>
19+
<RowDefinition Height="*"></RowDefinition>
20+
<RowDefinition Height="Auto"></RowDefinition>
21+
</Grid.RowDefinitions>
22+
<Grid Margin="10" Grid.Row="0" Name="OptionPanel">
23+
<Grid.RowDefinitions>
24+
<RowDefinition Height="Auto"/>
25+
<RowDefinition Height="Auto"/>
26+
<RowDefinition Height="*"/>
27+
</Grid.RowDefinitions>
28+
<Grid HorizontalAlignment="Stretch" Grid.Row="0" VerticalAlignment="Center">
2429
<Grid.ColumnDefinitions>
2530
<ColumnDefinition Width="Auto"/>
2631
<ColumnDefinition Width="*"/>
2732
<ColumnDefinition Width="Auto"/>
2833
</Grid.ColumnDefinitions>
29-
<Label Content="LogName"
34+
<Label Content="LogName"
3035
Margin="10,10,10,10"
3136
VerticalAlignment="Center"
32-
HorizontalAlignment="Left"
33-
Grid.Column="0"
37+
HorizontalAlignment="Left"
38+
Grid.Column="0"
3439
/>
35-
<TextBox HorizontalContentAlignment="Left"
40+
<TextBox HorizontalContentAlignment="Left"
3641
VerticalContentAlignment="Center"
3742
HorizontalAlignment="Stretch"
3843
TextAlignment="Left"
@@ -41,66 +46,89 @@
4146
MinWidth="200" MaxWidth="1000"
4247
Grid.Column="1"
4348
/>
44-
<Button Name="OpenLogButton"
45-
Grid.Column="2"
46-
Content="Open"
49+
<Button Name="OpenLogButton"
50+
Grid.Column="2"
51+
Content="Open"
4752
IsVisible="{Binding IsEnableFilePathOpenButton}"
48-
Click="OnLogOpenButtonClicked"/>
49-
</Grid>
50-
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
53+
IsEnabled="{Binding IsEnableFilePathOpenButton}"
54+
Click="OnLogOpenButtonClicked"/>
55+
<Button Name="OpenLogNameButton"
56+
Grid.Column="2"
57+
Content="Show LogName"
58+
IsVisible="{Binding IsOpenLogNameButtonEnabled}"
59+
IsEnabled="{Binding IsOpenLogNameButtonEnabled}"
60+
Click="OnShowLogNameClicked"
61+
/>
62+
</Grid>
63+
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="1">
5164
<Grid.ColumnDefinitions>
5265
<ColumnDefinition Width="Auto"/>
5366
<ColumnDefinition Width="Auto"/>
5467
</Grid.ColumnDefinitions>
55-
<Label Content="PathType"
68+
<Label Content="PathType"
5669
Margin="10,10,10,10"
5770
HorizontalAlignment="Left"
5871
VerticalAlignment="Center"
5972
Grid.Column="0"/>
60-
<!--<TextBox Margin="10,10,10,10"
73+
<!--<TextBox Margin="10,10,10,10"
6174
HorizontalAlignment="Stretch"
6275
TextAlignment="Left"
6376
VerticalContentAlignment="Center"
6477
Text="{Binding Path=PathType, Mode=TwoWay,Converter={StaticResource PathTypeConverter}}"/>-->
6578
<ComboBox
66-
HorizontalAlignment="Stretch"
67-
Margin="10"
68-
ItemsSource="{Binding PathTypes}"
69-
SelectedValue="{Binding CurrentSelected}"
70-
Grid.Column="1"
79+
HorizontalAlignment="Stretch"
80+
Margin="10"
81+
ItemsSource="{Binding PathTypes}"
82+
SelectedValue="{Binding CurrentSelected}"
83+
Grid.Column="1"
7184
>
72-
<ComboBox.ItemTemplate>
73-
<DataTemplate>
74-
<Label Content="{Binding DisplayName}"/>
75-
</DataTemplate>
76-
</ComboBox.ItemTemplate>
77-
</ComboBox>
78-
</Grid>
79-
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" MaxHeight="300" MaxWidth="{Binding #OptionPanel.Bounds.Width}">
80-
<StackPanel Orientation="Vertical" Margin="10">
81-
<CheckBox Name="UseRawQuery" Content="raw query" Margin="10" IsChecked="{Binding UseRawQuery}"/>
82-
<TextBox Name="RawQueryInput" Margin="10" Text="{Binding RawQuery}" IsEnabled="{Binding UseRawQuery}"/>
83-
<Border BorderThickness="1" BorderBrush="Gray"/>
84-
<StackPanel Orientation="Horizontal">
85-
<CheckBox Content="Since:" IsChecked="{Binding UseBeginDate}" Margin="10"/>
86-
<DatePicker Name="BeginDate" SelectedDate="{Binding BeginDate}" IsEnabled="{Binding UseBeginDate}"/>
87-
<TimePicker Name="BeginTime" SelectedTime="{Binding BeginTime}" IsEnabled="{Binding UseBeginDate}"/>
88-
</StackPanel>
89-
<StackPanel Orientation="Horizontal">
90-
<CheckBox Content="Until:" IsChecked="{Binding UseEndDate}" Margin="10"/>
91-
<DatePicker Name="EndDate" SelectedDate="{Binding EndDate}" IsEnabled="{Binding UseEndDate}"/>
92-
<TimePicker Name="EndTime" SelectedTime="{Binding EndTime}" IsEnabled="{Binding UseEndDate}"/>
93-
</StackPanel>
94-
<CheckBox Content="filter providers(separeted by ',')" Margin="10" IsChecked="{Binding UseProviderNames}"/>
95-
<TextBox Text="{Binding ProviderNames}" IsEnabled="{Binding UseProviderNames}"/>
96-
</StackPanel>
97-
</ScrollViewer>
98-
<!--<Expander Header="Advanced" Grid.Row="2" HorizontalAlignment="Stretch" MaxHeight="300">
85+
<ComboBox.ItemTemplate>
86+
<DataTemplate>
87+
<Label Content="{Binding DisplayName}"/>
88+
</DataTemplate>
89+
</ComboBox.ItemTemplate>
90+
</ComboBox>
91+
</Grid>
92+
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" Grid.Row="2">
93+
<StackPanel Orientation="Vertical" Margin="10">
94+
<CheckBox Name="UseRawQuery" Content="raw query" Margin="10" IsChecked="{Binding UseRawQuery}"/>
95+
<TextBox Name="RawQueryInput" Margin="10" Text="{Binding RawQuery}" IsEnabled="{Binding UseRawQuery}"/>
96+
<Border BorderThickness="1" BorderBrush="Gray"/>
97+
<StackPanel Orientation="Horizontal">
98+
<CheckBox Content="Since:" IsChecked="{Binding UseBeginDate}" Margin="10"/>
99+
<DatePicker Name="BeginDate" SelectedDate="{Binding BeginDate}" IsEnabled="{Binding UseBeginDate}"/>
100+
<TimePicker Name="BeginTime" SelectedTime="{Binding BeginTime}" IsEnabled="{Binding UseBeginDate}"/>
101+
</StackPanel>
102+
<StackPanel Orientation="Horizontal">
103+
<CheckBox Content="Until:" IsChecked="{Binding UseEndDate}" Margin="10"/>
104+
<DatePicker Name="EndDate" SelectedDate="{Binding EndDate}" IsEnabled="{Binding UseEndDate}"/>
105+
<TimePicker Name="EndTime" SelectedTime="{Binding EndTime}" IsEnabled="{Binding UseEndDate}"/>
106+
</StackPanel>
107+
<CheckBox Content="filter providers(separeted by ',')" Margin="10" IsChecked="{Binding UseProviderNames}"/>
108+
<Grid>
109+
<Grid.ColumnDefinitions>
110+
<ColumnDefinition Width="*"/>
111+
<ColumnDefinition Width="Auto"/>
112+
</Grid.ColumnDefinitions>
113+
<TextBox Text="{Binding ProviderNames}" IsEnabled="{Binding UseProviderNames}" Grid.Column="0" Margin="10"/>
114+
<Button Content="Show Providers" Grid.Column="1" Margin="10" Click="OnShowProviderNamesClicked"/>
115+
</Grid>
116+
<CheckBox Content="filter by level" Margin="10" IsChecked="{Binding UseFilterByLevel}"/>
117+
<StackPanel Orientation="Horizontal">
118+
<CheckBox Content="Critical" Margin="10" IsChecked="{Binding IsCriticalChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
119+
<CheckBox Content="Error" Margin="10" IsChecked="{Binding IsErrorChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
120+
<CheckBox Content="Warning" Margin="10" IsChecked="{Binding IsWarningChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
121+
<CheckBox Content="Information" Margin="10" IsChecked="{Binding IsInformationChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
122+
<CheckBox Content="Verbose" Margin="10" IsChecked="{Binding IsVerboseChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
123+
</StackPanel>
124+
</StackPanel>
125+
</ScrollViewer>
126+
<!--<Expander Header="Advanced" Grid.Row="2" HorizontalAlignment="Stretch" MaxHeight="300">
99127
</Expander>-->
100-
</StackPanel>
101-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" VerticalAlignment="Bottom">
102-
<Button Content="OK" Command="{ Binding OkCommand }" Margin="10" Padding="10"/>
103-
<Button Content="Cancel" Command="{ Binding CancelCommand }" Margin="10" Padding="10"/>
104-
</StackPanel>
105-
</Grid>
128+
</Grid>
129+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" VerticalAlignment="Bottom">
130+
<Button Content="OK" Command="{ Binding OkCommand }" Margin="10" Padding="10"/>
131+
<Button Content="Cancel" Command="{ Binding CancelCommand }" Margin="10" Padding="10"/>
132+
</StackPanel>
133+
</Grid>
106134
</Window>

src/WEventViewer/OpenLogWindow.axaml.cs

+16
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,20 @@ public async void OnLogOpenButtonClicked(object? sender, RoutedEventArgs routedE
3737
}
3838
}
3939
}
40+
public void OnShowLogNameClicked(object? sender, RoutedEventArgs routedEventArgs)
41+
{
42+
var logNameWindow = new LogNameWindow()
43+
{
44+
DataContext = new LogNameViewModel()
45+
};
46+
logNameWindow.Show();
47+
}
48+
public void OnShowProviderNamesClicked(object? sender, RoutedEventArgs routedEventArgs)
49+
{
50+
var w = new ProviderNamesWindow()
51+
{
52+
DataContext = new ProviderNameWindowViewModel()
53+
};
54+
w.Show();
55+
}
4056
}

src/WEventViewer/ViewModel/OpenLogWindowViewModel.cs

+55-11
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,6 @@ internal partial class OpenLogWindowViewModel : INotifyPropertyChanged
6868
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LogName)));
6969
}
7070
}
71-
//PathType _PathType = PathType.LogName;
72-
//public PathType PathType
73-
//{
74-
// get => _PathType;
75-
// set
76-
// {
77-
// _PathType = value;
78-
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PathType)));
79-
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsEnableFilePathOpenButton)));
80-
// }
81-
//}
8271
PathTypeDefinition _CurrentSelected = _PathTypes[0];
8372
public PathTypeDefinition CurrentSelected
8473
{
@@ -88,9 +77,12 @@ public PathTypeDefinition CurrentSelected
8877
_CurrentSelected = value;
8978
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentSelected)));
9079
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsEnableFilePathOpenButton)));
80+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsOpenLogNameButtonEnabled)));
9181
}
9282
}
9383

84+
public bool IsOpenLogNameButtonEnabled => _CurrentSelected != null && _CurrentSelected.PathType == PathType.LogName;
85+
9486
[RelayCommand]
9587
void OnPathTypeChanged(Avalonia.Controls.SelectionChangedEventArgs evargs)
9688
{
@@ -147,6 +139,7 @@ public bool UseRawQuery
147139
UseBeginDate = false;
148140
UseEndDate = false;
149141
UseProviderNames = false;
142+
UseFilterByLevel = false;
150143
}
151144
}
152145
}
@@ -184,6 +177,34 @@ string BuildQuery()
184177
var providerConditions = string.Join(" or ", ProviderNames.Split(',').Select(x => $"@Name = '{x.Trim()}'"));
185178
conditions.Add($"Provider[{providerConditions}]");
186179
}
180+
if (UseFilterByLevel)
181+
{
182+
var levelConditions = new List<string>();
183+
if(IsCriticalChecked)
184+
{
185+
levelConditions.Add("Level=1");
186+
}
187+
if(IsErrorChecked)
188+
{
189+
levelConditions.Add("Level=2");
190+
}
191+
if(IsWarningChecked)
192+
{
193+
levelConditions.Add("Level=3");
194+
}
195+
if(IsInformationChecked)
196+
{
197+
levelConditions.Add("Level=4");
198+
}
199+
if(IsVerboseChecked)
200+
{
201+
levelConditions.Add("Level=5");
202+
}
203+
if (levelConditions.Count > 0)
204+
{
205+
conditions.Add($"({string.Join(" or ", levelConditions)})");
206+
}
207+
}
187208
if (conditions.Count > 0)
188209
{
189210
return $"*[System[{string.Join(" and ", conditions)}]]";
@@ -304,5 +325,28 @@ public bool UseProviderNames
304325
}
305326
}
306327
public string ProviderNames { get; set; } = string.Empty;
328+
bool _UseFilterByLevel = false;
329+
public bool UseFilterByLevel
330+
{
331+
get => _UseFilterByLevel;
332+
set
333+
{
334+
var changed = _UseFilterByLevel != value;
335+
_UseFilterByLevel = value;
336+
if (changed)
337+
{
338+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(UseFilterByLevel)));
339+
if(UseRawQuery && value)
340+
{
341+
UseRawQuery = false;
342+
}
343+
}
344+
}
345+
}
346+
public bool IsCriticalChecked { get; set; } = false;
347+
public bool IsErrorChecked { get; set; } = false;
348+
public bool IsWarningChecked { get; set; } = false;
349+
public bool IsInformationChecked { get; set; } = false;
350+
public bool IsVerboseChecked { get; set; } = false;
307351
}
308352
}

0 commit comments

Comments
 (0)