Click here to Skip to main content
15,894,343 members
Articles / Web Development / ASP.NET

Clog: Client Logging, Silverlight Edition

Rate me:
Please Sign up or sign in to vote.
4.84/5 (55 votes)
16 Apr 2009CPOL14 min read 277.4K   3.1K   112  
A customizable log provider system that allows you to harness your existing logging system to log client side messages to your server. Includes a Silverlight interface and Log Viewer.
<UserControl x:Class="DanielVaughan.Logging.Silverlight.UI.LogViewer"
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="500" Height="500">
	<UserControl.Resources>
		<Style x:Key="LogPanel" TargetType="StackPanel">
			<Setter Property="Margin" Value="10"/>
			<Setter Property="Width" Value="55"/>
			<Setter Property="Height" Value="55"/>
			<Setter Property="Background">
				<Setter.Value>
					<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
						<GradientStop Color="#FFFFF098"/>
						<GradientStop Color="#FFFFF9D4" Offset="1"/>
					</LinearGradientBrush>
				</Setter.Value>
			</Setter>
		</Style>

		<Style x:Key="LogLevel" TargetType="TextBlock">
			<Setter Property="HorizontalAlignment" Value="Center"/>
			<Setter Property="VerticalAlignment" Value="Center"/>
			<Setter Property="FontSize" Value="11"/>
			<Setter Property="FontWeight" Value="Bold"/>
			<Setter Property="Foreground" Value="DarkSlateGray"/>
		</Style>

		<Style x:Key="OccuredAt" TargetType="TextBlock">
			<Setter Property="HorizontalAlignment" Value="Center"/>
			<Setter Property="VerticalAlignment" Value="Center"/>
			<Setter Property="FontSize" Value="11"/>
			<Setter Property="Foreground" Value="DarkSlateGray"/>
		</Style>

		<Style x:Key="TitleBlock" TargetType="TextBlock">
			<Setter Property="FontFamily" Value="Trebuchet MS"/>
			<Setter Property="TextAlignment" Value="Left"/>
			<Setter Property="VerticalAlignment" Value="Top"/>
			<Setter Property="FontSize" Value="12"/>
			<Setter Property="TextWrapping" Value="Wrap"/>
		</Style>
	</UserControl.Resources>
	
	
    <Grid x:Name="LayoutRoot" Background="White">
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*"/>
			<ColumnDefinition Width="200"/>
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="*" />
			<RowDefinition Height="auto" />
			<RowDefinition Height="auto" />
		</Grid.RowDefinitions>
		<StackPanel>
			<TextBlock>Log Entries:</TextBlock>
			<ListBox x:Name="ListBox_Entries" Height="250">
				<ListBox.ItemTemplate>
					<DataTemplate>
						<StackPanel Orientation="Horizontal">
							<StackPanel>
								<TextBlock Text="{Binding OccuredAt}" Style="{StaticResource OccuredAt}" /> 
							<TextBlock Text="{Binding LogLevel}" Style="{StaticResource LogLevel}" />                                                                                   
						</StackPanel>
							<!-- Log Entry Title-->
							<TextBlock Text="{Binding Message}" Margin="5" Style="{StaticResource TitleBlock}"/>
                    </StackPanel>
					</DataTemplate>
				</ListBox.ItemTemplate>
				<Border Padding="3" Background="#E6BB8A" CornerRadius="5">
					<ScrollViewer x:Name="ScrollViewerElement">
						<ItemsPresenter />
					</ScrollViewer>
				</Border>
			</ListBox>
		</StackPanel>
		<TextBlock x:Name="TextBlock_Entry" Grid.Column="1" Grid.Row="0" TextWrapping="Wrap" VerticalAlignment="Top"></TextBlock>
		<StackPanel Grid.ColumnSpan="2" Grid.Row="2">
			<TextBlock>Internal Messages:</TextBlock>
			<ScrollViewer>
				<TextBox x:Name="TextBlock_Messages"></TextBox>
			</ScrollViewer>
		</StackPanel>

		<!--<TextBlock x:Name="TextBlock_Version" Grid.ColumnSpan="2" Grid.Row="3"></TextBlock>-->
    </Grid>
</UserControl>

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)


Written By
Engineer
Switzerland Switzerland
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.

Previously Daniel was a nine-time Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company.

Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.

Daniel is the developer behind several acclaimed mobile apps including Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably Codon.

Would you like Daniel to bring value to your organisation? Please contact

Blog | Twitter


Xamarin Experts
Windows 10 Experts

Comments and Discussions