It occurred to me, tonight, as I copied and pasted the same generic log4net config to a new project that I do this because this is my favourite log4net configuration. And, if it's a good enough starting point for all my projects then it may be of interest to others.
This config writes to two appenders; the console and a file appender. The file appender is pretty neat in that it;
Creates log files in a logs/ folder
The standard file is "general.txt"
This file grows on each iteration, until it reaches a maximum size of 2MB
When it hits 2MB, the file is renamed and a new "general.txt" file is opened
Maintains a maximum of 10 renamed / archived log files (so, a total of 20MB [...]
log4net is a fantastic library for adding configurable logging to your project. Configuration is relatively straightforward but I always get caught out when adding it to a new project.
So, here's a cribsheet for adding it in…
Download the latest stable library, and add a reference to it within your own project
Ensure that you have an app.config file
Add the configSection for log4net (see samples, below)
Add the log4net section (another sample)
Add an ILog object to your class
And, the bit I always forget, add the [assembly] entry to the top of your class
In your app.config file, add log4net to the <configSections> (if you don't have one of these, it goes at the next level down from the <configuration> element;
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
Next, [...]
I did a bit of research while trying to figure out what I was going to move my blog to. I felt I was just too constrained at BlogSpot, and the ability to add tools / widgest / themes or to otherwise customise the blog was just too limiting.
Anyway (#1) I elected to go with WordPress because it seems open enough, powerful enough and simple enough (some oxymoron going on there) for what I wanted.
But the editor!!! Jeez. WordPress ships with a thing called TinyMCE which is actually pretty feature-powerful. But, a couple of postings in and the pain shines through.
Biggest gripes are;
#2 constantly having to switch between View and HTML mode to get the effect you want
#1 then [...]
Blog moved to Wordpress [...]
The problem is that you need to pass your parameters to your Silverlight class and hopefully deal with them. First and foremost, how do you recognise that you’ve been called? Well, via the OnNavigatedTo event… this event is fired for every Silverlight page.
OK, so we captured the OnNavigatedTo event. What next? Well, next we try to decode the uri that was passed to the SilverLight app. Let’s pretend for a moment that we were called via “http:<YourSource>?title=myTitle&search=special”
We now have two session variables set; title=myTitle and search=special
So, how do we decode these? The easiest way is to use the SilverLight libraries to query the NavigationContext object;
if (this.NavigationContext.QueryString.ContainsKey("title")) this.Title = this.NavigationContext.QueryString["title"];
if (this.NavigationContext.QueryString.ContainsKey("search")) searchType [...]
The problem
Build a navigation tree that allows users to navigate to specific static pages, from static entries in the menus, and to pages that are built dynamically based on selections from the menu.
The Solution in a picture
The solution in code
Build the static menu selections in xaml, being sure to name each of the major headings with “Tag” entries;
<Grid x:Name="LayoutRoot">
<controls:TreeView x:Name="treeview"
BorderThickness="0"
Margin="0"
[...]
Obvious, really, but I spent ages chasing down how to bind some kind of POCO to a XAML display;
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="300" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
[...]
How do you handle the situation where your new Silverlight page needs to shout a warning or error, and then die? No idea, but this is how I do it…
Originally, I was quite scared of my Silverlight pages throwing an exception and then I realised that this was just another object and if we throw an exception, hopefully let the user know, and bail out, then that’s fine.
So the pattern I am now working with is this;
Constructor – set up the load operations
Page_Loaded events – bind the XAML objects to the retrieved data
On any error; display a meaningful message, in a semi-modal window
Navigate back to a safe place (e.g. /home)
What do I mean by “semi-modal”? Well, from the user’s perspective, it [...]
I’ve been toying with Silverlight over the last couple of weeks and, I have to say, it’s much more complete than ASP.Net ever was (**). Lots of new paradigms to get my head around, of course, but overall it’s a very complete solution for an RIA.
Anyway, to the point of this posting; the new (in Silverlight 3.0) Navigation Framework is great; it allows you to present a common interface and have new pages display in a know part of the browser window, supports browser back/forward, and URL rewrites. See here for more information.
If you are inside a page that is controlled by the framework, then you are able to call on the NavigationService.Navigate method to divert control to a new XAML [...]
So you want to start at a top level folder, and then process all the folders beneath… Maybe you really do want to look at every file (maybe count the total size of the folder), maybe you want to process all the XML files there. The most obvious route is to recursively search through each folder;
static void Main(string[] args)
{
string startFolder = @"C:\temp";
List<string> contents = new List<string>();
foreach (string dir in [...]
|
|