Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Applications » Downloads
 
Add your own
alternative version

C# WPF Log4Net Viewer

, 15 Oct 2009 CPOL
Log4Net XML log viewer
LogViewer.zip
LogViewer
bin
Debug
LogViewer.exe
LogViewer.vshost.exe
LogViewer.vshost.exe.manifest
LogViewer.csproj.user
LogViewer.suo
Properties
Settings.settings
Resources
Images
arrow_left.png
arrow_right.png
find.png
Skins
<Window x:Class="LogViewer.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:LogViewer"
    Title="LogViewer" Height="800" Width="700"
    SizeToContent="WidthAndHeight"
    ResizeMode="CanResizeWithGrip" 
    AllowDrop="True"
    Closing="Window_Closing">
    <DockPanel Background="{DynamicResource Brush_HeaderBackground}">
        <Grid DockPanel.Dock="Top">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Menu Grid.Column="0" Name="menu1" Height="22" HorizontalAlignment="Stretch">
                    <MenuItem Header="File" Foreground="White">
                        <MenuItem Header="Open" Click="MenuFileOpen_Click" />
                        <Separator BorderThickness="1" />
                        <local:RecentFileList x:Name="RecentFileList"/>
                        <Separator BorderThickness="1" />
                        <MenuItem Header="Exit" Click="MenuFileExit_Click"/>
                    </MenuItem>
                    <MenuItem Header="Refresh" Click="MenuRefresh_Click" Foreground="White"/>
                    <MenuItem Header="Filter" Click="MenuFilter_Click" Foreground="White"/>
                    <MenuItem Header="About" Click="MenuAbout_Click" Foreground="White"/>
                </Menu>
                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" Background="{DynamicResource Brush_HeaderBackground}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="10"/>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                    <StackPanel Grid.Column="1" Orientation="Horizontal">
                        <Image x:Name="imageError" Height="16" Width="16" Visibility="Hidden" VerticalAlignment="Center"/>
                        <Label x:Name="labelErrorCount" Visibility="Hidden" VerticalAlignment="Center" />
                    </StackPanel>
                    <StackPanel Grid.Column="2" Orientation="Horizontal">
                        <Image x:Name="imageInfo" Height="16" Width="16" Visibility="Hidden" VerticalAlignment="Center"/>
                        <Label x:Name="labelInfoCount" Visibility="Hidden" VerticalAlignment="Center"/>
                    </StackPanel>
                    <StackPanel Grid.Column="3" Orientation="Horizontal">
                        <Image x:Name="imageWarn" Height="16" Width="16" Visibility="Hidden" VerticalAlignment="Center"/>
                        <Label x:Name="labelWarnCount" Visibility="Hidden" VerticalAlignment="Center"/>
                    </StackPanel>
                    <StackPanel Grid.Column="4" Orientation="Horizontal">
                        <Image x:Name="imageDebug" Height="16" Width="16" Visibility="Hidden"/>
                        <Label x:Name="labelDebugCount" Visibility="Hidden" VerticalAlignment="Center"/>
                    </StackPanel>
                </StackPanel>
            </Grid>
            <Grid Grid.Row="1">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                </Grid>
                <StackPanel Grid.Column="0" Orientation="Horizontal">
                    <Label Foreground="#FFC3C9E9"
                           FontWeight="Normal"
                           FontSize="16"
                           FontFamily="Calibri"
                           Content="Path:"/>
                    <TextBox Name="textboxFileName"
                           Foreground="Orange"
                           FontWeight="Normal"
                           FontSize="16"
                           FontFamily="Calibri"
                           HorizontalAlignment="Stretch"
                           Background="Transparent"                       
                           BorderThickness="0"
                           Margin="2,2,2,2" Width="400" />
                </StackPanel>
                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                    <Image Name="image2" Width="16" Height="16" Margin="2" Source="/LogViewer;component/Resources/Images/find.png" VerticalAlignment="Center"/>
                    <Label Name="label3" Foreground="#FFC3C9E9" Content="Find:" VerticalAlignment="Center"/>
                    <TextBox Height="20" Name="textBoxFind" Width="120" VerticalAlignment="Center" AcceptsReturn="False" KeyDown="textBoxFind_KeyDown" />
                    <Button Height="23" Name="buttonFindNext" Width="27" Click="buttonFindNext_Click" Cursor="Hand" VerticalAlignment="Center">
                        <Button.Template>
                            <ControlTemplate>
                                <Image Width="16" Height="16" ToolTip="Find Next" Source="/LogViewer;component/Resources/Images/arrow_right.png" />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                    <Button Height="23" Name="buttonFindPrevious" Width="23" Click="buttonFindPrevious_Click" Cursor="Hand" VerticalAlignment="Center">
                        <Button.Template>
                            <ControlTemplate>
                                <Image Width="16" Height="16" ToolTip="Find Previous" Source="/LogViewer;component/Resources/Images/arrow_left.png" />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>
                
            </Grid>
        </Grid>        
        <StatusBar Height="23" DockPanel.Dock="Bottom" Foreground="#FFE9EEF0" Background="{DynamicResource Brush_StatusBarBackground}">
            <StatusBarItem Content="Ready"/>
        </StatusBar>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="300"/>
                <RowDefinition Height="130" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <GridSplitter Name="gridSplitter1" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Grid.Row="0" Height="4">
                <GridSplitter.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="LightGray" Offset="0"/>
                        <GradientStop Color="DarkGray" Offset="1"/>
                    </LinearGradientBrush>
                </GridSplitter.Background>
            </GridSplitter>
            <!-- List View -->
            <Border BorderThickness="4,4,4,4" Margin="0,0,0,10">
                <ListView Name="listView1" 
                      Grid.Row="0" 
                      ItemsSource= "{Binding ElementName=Window1, Path=Entries}" 
                      AllowDrop="True"
                      SelectionChanged="listView1_SelectionChanged" 
                      Drop="listView1_Drop">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Level}" Value="ERROR">
                                    <Setter Property="Background" Value="Red"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Level}" Value="INFO">
                                    <Setter Property="Background" Value="Green"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Level}" Value="DEBUG">
                                    <Setter Property="Background" Value="LightGray"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Level}" Value="WARN">
                                    <Setter Property="Background" Value="Yellow"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Level}" Value="FATAL">
                                    <Setter Property="Background" Value="Red"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Level}" Value="COMPRESSION">
                                    <Setter Property="Background" Value="Gainsboro" />
                                </DataTrigger>
                            </Style.Triggers>
                            <Setter Property="Height" Value="20"/>
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.View>
                        <GridView x:Name="GridView1">
                            <GridViewColumn Header="Item" DisplayMemberBinding="{Binding Item}"  />
                            <GridViewColumn Header="TimeStamp" DisplayMemberBinding="{Binding TimeStamp}"/>
                            <GridViewColumn Header="">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Image Source="{Binding Image}" Width="16" Height="16" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Level" DisplayMemberBinding="{Binding Level}"/>
                            <GridViewColumn Header="Thread" DisplayMemberBinding="{Binding Thread}"/>
                            <GridViewColumn Header="Message" DisplayMemberBinding="{Binding Message}" Width="250" />
                            <GridViewColumn Header="MachineName" DisplayMemberBinding="{Binding MachineName}"/>
                            <GridViewColumn Header="HostName" DisplayMemberBinding="{Binding HostName}"/>
                            <GridViewColumn Header="UserName" DisplayMemberBinding="{Binding UserName}"/>
                            <GridViewColumn Header="App" DisplayMemberBinding="{Binding App}"/>
                            <GridViewColumn Header="Class" DisplayMemberBinding="{Binding Class}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Border>
            <!-- Data Fields and Tab Control  -->
            <Grid Grid.Row="1" Margin="15,0,15,10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="10"/>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="10"/>
                </Grid.RowDefinitions>

                <!-- Row 1-->
                <Image Name="image1" Width="16" Height="16" Grid.Column="0" Grid.Row="1" />
                <TextBox Name="textBoxLevel" Height="23" Grid.Column="1" Grid.Row="1" />
                <Label Name="label1" Height="28" Grid.Column="2" Grid.Row="1">Time Stamp</Label>
                <TextBox Name="textBoxTimeStamp" Height="23" Grid.Column="3" Grid.Row="1" />
                <Label Name="label2" Height="28" Grid.Column="4" Grid.Row="1">Machine Name</Label>
                <TextBox Name="textBoxMachineName" Height="23" Grid.Column="5" Grid.Row="1" />
                <Label Name="labelThread" Grid.Column="6" Grid.Row="1">Thread</Label>
                <TextBox Name="textBoxThread" Grid.Column="7" Grid.Row="1"/>

                <!-- Row 2 -->
                <Label Name="labelItem" Height="28" Grid.Column="0" Grid.Row="2">Item</Label>
                <TextBox Name="textBoxItem" Height="23" Grid.Column="1" Grid.Row="2" />
                <Label Name="label4" Height="28" Grid.Column="2" Grid.Row="2">Host Name</Label>
                <TextBox Name="textBoxHostName" Height="23" Grid.Column="3" Grid.Row="2"/>
                <Label Name="label5" Height="28" Grid.Column="4" Grid.Row="2">User Name</Label>
                <TextBox Name="textBoxUserName" Height="23" Grid.Column="5" Grid.Row="2"/>
                <Label Name="label6" Height="28" Grid.Column="6" Grid.Row="2">App</Label>
                <TextBox Name="textBoxApp" Height="23" Grid.Column="7" Grid.Row="2"/>

                <!-- Row 3-->
                <Label Name="label7" Height="28" Grid.Column="0" Grid.Row="3">Class</Label>
                <TextBox Name="textBoxClass" Height="23" Grid.Column="1" Grid.Row="3"/>
                <Label Name="label8" Height="28" Grid.Column="2" Grid.Row="3">Method</Label>
                <TextBox Name="textBoxMethod" Height="23" Grid.Column="3" Grid.Row="3"/>
                <Label Name="label9" Height="28" Grid.Column="4" Grid.Row="3">Line</Label>
                <TextBox Name="textBoxLine" Height="23" Grid.Column="5" Grid.Row="3"/>

                <!-- Row 4-->
                <Label Name="labelFile" Height="23" Grid.Column="0" Grid.Row="4">File</Label>
                <TextBox Name="textBoxfile" Height="28" Grid.Column="1" Grid.ColumnSpan="7" Grid.Row="4"/>

            </Grid>
            <TabControl Name="tabControl1" Grid.Row="2" Margin="15,0,15,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <TabItem Header="Message">
                    <TextBox Name="textBoxMessage" TextWrapping="Wrap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" BorderThickness="0" />
                </TabItem>
                <TabItem Header="Throwable">
                    <TextBox Name="textBoxThrowable" TextWrapping="Wrap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" BorderThickness="0"/>
                </TabItem>
            </TabControl>
        </Grid>
    </DockPanel>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ken C. Len
Software Developer (Senior) LEN Associates Inc.
United States United States
Years of software consulting and software development using Microsoft development products such as Microsoft Content Management System, SQL Server Reporting Service, ASP.Net C# VB.Net, HTML and javascript web development, Visual Studio add-on development, C++ MFC/ATL and COM+ development, and ActiveX components.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411022.1 | Last Updated 15 Oct 2009
Article Copyright 2008 by Ken C. Len
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid