log4net logging aspnet comments suggest edit

UPDATE: I wrote a post with notes on getting this to work with ASP.NET 2.0.

Looking around, I noticed a lot of people struggling with getting Log4Net to work with their web applications (ASP.NET 1.1). I’m not going to spend a lot of time digging into Log4Net here, as you can do a Google search for that. But I will give you a quick and dirty guide to quickly getting it set up for a website. Bar of soap not included.

Using a Separate Config File

Although you can put your Log4Net configuration settings within the web.config file, I prefer to use a separate configuration file. Log4Net is a bit of an elitist. It won’t dare put a FileSystemWatcher on web.config nor App.config. However, if you tell it to use its own config file, it will gladly monitor that log file and update its settings on the fly when the file changes.

Specifying the Log4Net Config File

If you use a separate config file, a quick and easy (and dirty) way to have your application find it is to place the config file in the webroot and add the following attribute to your AssemblyInfo.cs file.

[assembly: log4net.Config.XmlConfigurator( 
ConfigFile="Log4Net.config",Watch=true )]

Declaring the Logger {.clear}

At the top of each class that I plan to use logging in, I declare a logger like so:

private static readonly ILog Log = LogManager.GetLogger( 

The reason I place a logger in each class is to scope it to that class. If you read the log4Net docs, you’ll see what I mean by this.

Using the Logger

Once you’ve declared the logger, you can call one its logging methods. Each method is named for the logging level. For example:

Log.Debug("This is a DEBUG level message.  
Typically your most VERBOSE level.");

Now whether that message shows up in your logs depends on how you’ve configured your appenders and the logging level you’ve set. Don’t understand what that means? Read the Log4Net introduction.

Sample Web Solution

In order to make all this discussion very concrete, I’ve gone ahead and did all your homework for you by creating a simple ASP.NET 1.1 web solution (Log4NetSampleSolution.zip ) using Visual Studio.NET 2003. After unzipping this solution, you should be able to build it and then view the default.aspx web page. This page will log a few very interesting messages of varying levels to three appenders.

Of special note is the use of the RollingFileAppender as seen in this snippet.

<appender name="RollingLogFileAppender"    

    <file value="..\Logs\\CurrentLog" />
    <appendToFile value="true" />
    <datePattern value="yyyyMMdd" />

    <rollingStyle value="Date" />
    <filter type="log4net.Filter.LevelRangeFilter">
        <acceptOnMatch value="true" />

        <levelMin value="INFO" />
        <levelMax value="FATAL" />

    <layout type="log4net.Layout.PatternLayout">
        value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />


Note that the file value (with backslashes escaped) points to ..\Logs\CurrentLog. This specifies that Log4Net will log to a file in a directory named Logs parallel to the webroot. You need to give the ASPNET user write permission to this directory, which is why it is generally a good idea to leave it out of the webroot. Not to mention the potential for an IIS misconfiguration that allows the average Joe to snoop through your logs.

comments suggest edit

My friend Walter points out some common sense advice about how not to get fired for the content of your blog. Of course this issue has been beaten to a pulp in the larger blogosphere, but one thing he mentioned caught my attention.

Of course most employers will probably never find any particular employees blog, and if they did they probably would not be offended.

You’d be surprised how easy it is for an employer to find your blog without even meaning to. Unless you restrict your content to something quite unrelated to any of your company’s interest, your content is almost certainly going to have posts that are related to your field. That’s when Google kicks in. The large majority of my referrals come from Google searches. Often from people searching for information on a particular technical problem I just happened to write about.

That’s why the solution is to hide your identity and lie lie lie!

comments suggest edit

Currently, the only plug-in model supported by RSS Bandit is the IBlogExtension interface. This is a very limited interface that allows developers to write a plug-in that adds a menu option to allow the user to manipulate a single feed item.

The ability to interact with the application from such a plug-in is very limited as the interface doesn’t define an interface to the application other than a handle. (For info on how to write an IBlogExtension plug-in, see this article.)

So last night I was thinking about an email that a user sent me. He wants to know how to add an intelligent module for filtering and classifying RSS feeds to RSS Bandit. This is for his thesis project.

Since that might not be a necessary feature for RSS Bandit at this point, I suggested that he implement it in a private build. RSS Bandit is open source and he can easily obtain the source code. But it occurred to me that there are hundreds of feature requests like this that have the potential to be great solutions in the future, but would be best implemented as a plug-in in the near term.

So as I sat there thinking about it, Torsten goes ahead and implements a prototype for it. Mind you, I hadn’t talked to Torsten nor Dare about this yet, but I’m sure it’s something we’ve all been thinking about. Especially as the number of feature requests continues to accumulate.

So what areas of extensibility might we want to support? Well there’s the callback on feed item download that Torsten implemented. That alone is quite useful. I can imagine building a plug-in that would score items based on how likely I’d want to see it or not. Thus it could sort items based on importance in a special feed. This would help with the increasingly large number of feeds I’m subscribed to.

Dare mentioned (and he’ll write more on this) the idea to support new data sources and formats. For example, it’d be interesting to build NNTP support as a plug-in.

I’d also like to build the ability to provide an interface for plug-in data storage. For example, suppose you build a plug-in that keeps statistics of your RSS feeds. You might want that stored with your settings so that when you synchronize RSS Bandit, your plug-in settings are synchronized as well.


Thinking far out there, perhaps adding the ability to support IE toolbars might be an option as I think some users actually use RSS Bandit as their primary browser.

The important thing is to design a nice interface to expose the RSS Bandit application to the plug-ins. In tandem we need to prioritize these extensibility options by looking at current feature requests and thinking about how many of them could be implemented as plug-ins.

comments suggest edit

Evolution of DevelopmentJet Brains released a free upgrade to their ReSharper product. Let me tell you, using this product feels like walking on land after a long stint trying to walk under water.

Recently, I was trying to write some code on a coworker’s computer and kept hitting funky key combinations that had no meaning on his machine since he didn’t have this installed. I had to actually type out a bunch of code that just spills out when using this add-in. It felt so stone age.

Just to be complete, I know many are fans of CodeRush for Visual Studio. I liked it enough, but the lack of Refactoring support was a problem for me, which is why I chose ReSharper.

comments suggest edit

Via Dare’s blog, I found this interesting post on Random Number Generation on Michael Brundage’s website. My undergrad thesis was on the topic of pseudorandom number generation so I thought I’d take the two classes he provided for a quick spin.

Unfortunately, the C# samples did not compile as is. In his post he discusses how the C++ samples are optimized. I figured I might be able to use them to guide changes to the C# port and could post the results here. Please note that I have not tested them yet and need to verify that my changes were correct. Enjoy and let me know if I got anything wrong.


public class MersenneTwister


    private ulong _index;

    private ulong[] _buffer = new ulong[624];


    /// <summary>

    /// Creates a new <see cref=”MersenneTwister”/> instance.

    /// </summary>

    public MersenneTwister()


        Random r = new Random();

        for (int i = 0; i < 624; i++)

            _buffer[i] = (ulong)r.Next();

        _index = 0;



    /// <summary>

    /// Returns a random long integer.

    /// </summary>

    /// <returns></returns>

    public ulong Random()


        if (_index == 624)


            _index = 0;

            long i = 0;

            ulong s;

            for (; i < 624 - 397; i++)


                s = (_buffer[i] & 0x80000000) | (_buffer[i+1] & 0x7FFFFFFF);

                _buffer[i] = _buffer[i + 397] \^ (s >> 1) \^ ((s & 1) * 0x9908B0DF);


            for (; i < 623; i++)


                s = (_buffer[i] & 0x80000000) | (_buffer[i+1] & 0x7FFFFFFF);

                _buffer[i] = _buffer[i - (624 - 397)] \^ (s >> 1) \^ ((s & 1) * 0x9908B0DF);



            s = (_buffer[623] & 0x80000000) | (_buffer[0] & 0x7FFFFFFF);

            _buffer[623] = _buffer[396] \^ (s >> 1) \^ ((s & 1) * 0x9908B0DF);


        return _buffer[_index++];




public sealed class R250Combined521


    private ulong r250_index;

    private ulong r521_index;

    private ulong[] r250_buffer = new ulong[250];

    private ulong[] r521_buffer = new ulong[521];


    /// <summary>

    /// Creates a new <see cref=”R250Combined521”/> instance.

    /// </summary>

    public R250Combined521()


        Random r = new Random();

        ulong i = 521;

        ulong mask1 = 1;

        ulong mask2 = 0xFFFFFFFF;


        while (i– > 250)


            r521_buffer[i] = (ulong)r.Next();


        while (i– > 31)


            r250_buffer[i] = (ulong)r.Next();

            r521_buffer[i] = (ulong)r.Next();




        Establish linear independence of the bit columns

        by setting the diagonal bits and clearing all bits above


        while (i– > 0)


            r250_buffer[i] = (((uint)r.Next()) mask1) & mask2;
            r521_buffer[i] = (((uint)r.Next()) mask1) & mask2;

            mask2 = mask2 \^ mask1;

            //mask2 \^= mask1;

            mask1 >>= 1;


        r250_buffer[0] = mask1;

        r521_buffer[0] = mask2;

        r250_index = 0;

        r521_index = 0;



    /// <summary>

    /// Returns a random long integer.

    /// </summary>

    /// <returns></returns>

    public ulong random()


        ulong i1 = r250_index;

        ulong i2 = r521_index;


        ulong j1 = i1 - (250-103);

        if (j1 < 0)

            j1 = i1 + 103;

        ulong j2 = i2 - (521-168);

        if (j2 < 0)

            j2 = i2 + 168;


        ulong r = (r250_buffer[j1] \^ r250_buffer[i1]);

        r250_buffer[i1] = r;

        ulong s = (r521_buffer[j2] \^ r521_buffer[i2]);

        r521_buffer[i2] = s;


        i1 = (i1 != 249) ? (i1 + 1) : 0;

        r250_index = i1;

        i2 = (i2 != 521) ? (i2 + 1) : 0;

        r521_index = i2;


        return r \^ s;



comments suggest edit

Yes folks, it’s true. After working a while in VS.NET, it suddenly stops and asks if I’d like to send an error report to Microsoft. Then it shuts down. Almost like clockwork. This creates a very good time for me to take a break, stretch, and meditate on how much work I just lost as I was just about to hit the save icon.

hosting sourcecontrol comments suggest edit

For my personal coding projects at home, I’ve been using the free one-user version of SourceGear vault for my personal source control needs. As you know, having proper source control is #1 on The Joel Test.

But since I’m embarking on a project with Micah who lives in San Francisco, we need something better than to host on my little Shuttle system at home. We need hosting!

After some preliminary research, I’m leaning towards a semi-dedicated server from WebHost4Life. The Basic plan includes 150 GB of bandwidth, 2000 MB of Space, 2GB of SQL Server 2000, ASP.NET 1.1, Sharepoint Team/Windows Services, and on and on. Plus, no setup fees, and it’s $79.35 a month. This is a LOT cheaper than an equivalent option at DataPipe. DataPipe offers 5 nine uptime, but I think the 3 nines will be adequate.

This server will host our source control (which requires SQL Server and .NET) as well as a staging site for our client. If you know of a better option, please leave a comment. I’ll let you know what we end up deciding.

comments suggest edit

Today, my boss, the CTO, announced that I’m leaving the company to join the adult movie industry. Don’t worry, I’m actually not out to challenge the supremacy of John Holmes. That just happens to be the typical way he likes to announce the departure of employees. I’m just joining the seeming legion of developers who are going independent.

I actually gave notice two weeks ago, but I had promised not to say anything until my company had a chance to figure out how to deliver the news. Hence I didn’t mention it on my blog. Not that any of my coworkers read my blog (I think). But just in case, I wanted to be true to my word.

It’s funny how keeping a secret from your blog can affect how much you write on your blog. It’s as if I was worried that I’d start writing about how Test Driven Development will save your soul and suddenly blurt out, “oh by the way, I’m leaving my company. oops!”.

The first big contract I’m working on is with my friend Micah, one of the smartest software architects you’ll meet (and you’d find that out if he kept a damn blog. hint hint!). He’s fluent in both .NET and Java (where I’m lacking). We’re hoping to also work with my friend Kyle, one of the smartest people I know across the board. We’re positioning ourselves as Solution Architects, or as my former CEO put it, we’re “portable CTOs”. I’ll write up more about what that means later, but essentially it means we’ll help our clients implement the right solution, not just sell them a solution based on a religious preference for a particular platform or custom development when a product would do.

If you’re in need of a portable CTO, software architect, grunt developer on a project, send me an email. I’m also looking to get into process improvement consulting etc… That’s something I have a lot of experience with that I’d like to capitalize on. This includes helping teams get started with TDD, NUnit, Cruise Control, etc… I’m also available for code reviews etc… Sometimes you just need an extra pair of eyes.

In any case, I’m very excited and anxious about this big transition. Now I’m head deep in studying tax law and health insurance policies. Wish me luck and advice is appreciated.

comments suggest edit

Don Park outlines an interesting potential solution to Google’s proposed Auto Link feature of its Toolbar. Essentially his solution is to allow content author’s to opt-in via tagging content for auto-linking.

The question I have about this is if you’re going to go to all the trouble to mark up your content in this way, why not just provide the link yourself? One benefit I do see is in the case of an ISBN number. As a content producer, I might link to Amazon. However, if my user has an account at BookPool, she might configure the auto-link toolbar to link ISBNs to that site instead.

Of course, in general, I might not want that since I’d prefer to get credit for links to Amazon. But that’s beside the point. If I opt in, it’s the potential to give users more control. This assumes that Google gives user that level of control.

Another question I have is if content authors start using this tag, what stops browsers from adding AutoLink to pages that opt-in? In effect, Don’s suggestion creates an extension to HTML and by being opt-in, anybody should be able to hook into that, not just Google.

I’m not sure Google would want to go that route. Microsoft had its hand slapped by attempting an auto-link. Google perhaps thinks it can squeeze by since it’s not a monopoly power on the desktop and it promises to “do no evil”. But by making AutoLink opt-in, that should in theory make it palatable for browsers such as IE and FireFox add that feature.

Ultimately, I think AutoLink would be a great feature if it was controlled by the users. A user could control links to addresses so that they go to his or her favorite mapping site and an ISBN would link to the user’s favorite bookseller.

comments suggest edit

My friends are always looking out for me. Apparently Tre (aka Macktastic Tre Flava) realized that as an elevated player, I was in dire need of a pimp name. So he helpfully sent me a link to the Pimp Name Generator one of the many useful utilities on PlayerAppreciate.com.

So from now an, all you suckas can call me Big Playah P Rock. My lovely wife will heretofore be known as Golden Brown Akumi Slim. Respect!

comments suggest edit

It’s really coming down out there. On the freeway today I started hydroplaning a bit. Be careful out there. I’ve been pretty quiet on this blog due to being very busy. I have some big personal news (no, we’re not pregnant) to announce, but I promised not to announce it till others announce it.

comments suggest edit

I want an add-in to my instant messaging apps whereby if someone responds to a message by me with just the word “ok”, it doesn’t pop an instant message window if I’ve closed the window. Perhaps it can filter any messages with just the word “ok” and flash the system tray or something. Anything. Just don’t get in my way.

comments suggest edit

My friend Thomas Wagner has a small epiphany of sorts. At first, I thought he was writing the biography of my first year at my current job. But apparently this is quite common among businesses.

Very frequently the profit center of a company drives the development schedule and also drives the pressure being excerted on a developer or team. Can you guess who the people are that drive most of the profit? Those crazy lunatics in the Sales Dept.! Yes, the flunkies who like to bend reality in order to make a deal. Those are the folks that set your schedule and drive your work.

Just the other day, I was working on a task that requires certain deliverables from the marketing team be in my hand before I can even begin. Of course those items were delivered late, but naturally I get several emails in the span of the day asking for the status with wording like

This is something a client is waiting to see and technically it’s already late. Yadda yadda please get it done ASAP.

My reply was [edited slightly to protect the guilty] (note the weird pronoun use as time travel is involved).

I’ll tell you what, I will personally bend space, time and reality so that the deliverables will have been delivered to me a week prior to the day they actually were. And then I will personally spike everyone’s water with SPEED so they will have been working faster this entire time, and I will swap out our networks with a 1 TB connection so data will have been transferred faster. Also, I’ll swap out our systems with quantum computers so that they too aren’t limited by the silly constraints of a linear time continuum.

Of course, we have to remember that Sales and Marketing guys have their own pressures and are human too. Sometimes they aren’t all flunkies and can even be intelligent and witty as his reply indicates:

I think I saw a quantum computer at the local pawn shop… crazy shit.

Afterwards I reminded myself not to be such a jackass to this guy. But then again, the more of a jackass I am, the funnier he gets.

comments suggest edit

There’s a house on fire a couple of blocks away. It’s a veritable light show down there with nearly 10 or so fire trucks arriving on the scene.

House Fire

comments suggest edit

I love Ian’s response to James Gosling’s opinion on .NET’s C++ support and it’s supposed inherent insecurity. It’s basically a “Booyah! In your face” piece as he bit by bit dissects Goslings arguments and presents a Java example that directly contradicts Gosling claim that type unsafety is incapable in Java.

Ian, you’re the man! If you’re in L.A., I need to buy you a pint.

It just goes to show that it’s not just Ballmer who spreads the FUD thick. It’s time to bridge the Java/.NET divide and be reasonable here. The “religious” wars aren’t worth the time and energy. Quit spreading FUD in both directions and realize that both technologies have their weaknesses and strengths. It’s really disappointing to see this type of FUD from someone as respected as Gosling. I guess I expect that sort of thing from Ballmer.

comments suggest edit

In his latest entry about life as a infrastructure reconstruction project manager in Baghdad, Mr. Serjak describes the security detail that drives him to an onsite location. One detail in particular struck me as funny.

Our lead Humvee’s job is to clear a path for us which he does by waving an assault rifle at anyone that gets too close. If that doesn’t get their attention, his favorite weapon seems to be half-liter water bottles. He tosses these like a Nolan Ryan fastball at the windshield of cars that don’t pull to the side of the road quickly enough in his estimation. He actually has a little rack of water bottles mounted inside the turret.

I seriously need to get a rack mount of water bottles for my car. That would come in quite handy for the L.A. free way. Can you see me chucking an Evian at grandma ahead of me for driving too slowly in the fast lane?

comments suggest edit

Dare announced the beta version for the Wolverine edition of RSS Bandit (version 1.3.x) today. You can read his announcement to see some of the nice features it includes.

I’ve been feverishly updating the documentation to take into account the new features and the updated look and feel. Documentation is hard work when you’re trying to keep up with developers as productive as Dare and Torsten.

One feature that wasn’t announced, but quietly added by yours truly, is the ability to configure keyboard shortcuts via an XML settings file. The reason this is not an “announced” feature is that we have yet to provide any GUI support for configuring these settings. Nor have I documented the format for these settings or the proper way to change them.

Assuredly, I will be working to post both documentation as well as a separate shortcut editing tool soon. For the adventursome, there is a beta of the editing tool in the Child Projects folder in CVS. You can edit the settings and save the result in the RSS Bandit Application Data folder to override the default settings.

In the long term, we’ll have to decide if this remains a separate tool for power users who demand this level of control and are willing to take the risk, or if it should be added to the main GUI.

comments suggest edit

I’ve kept a couple of other blogs before, but this is my first with staying power. My blog new year resolutions include being even more irreverent, geeky, rash, and misguided (if even possible). It’s been one year, and I recently passed the 500 post mark without even noticing (I hate missing an opportunity to party).

If you’re a regular reader (hi Mom, Dad, Wife), do you realize that there’s much better drivel out there? But you probably read this blog for the same reason I read yours, you’re trying to expunge some latent guilt by self flagellation (Ignore the fact that the phrase “self flagellation” is redundant.). I hope that works out for you.

Seriously though, I’ve been surprised by the quality of comments I receive on my postings. I may have a few readers, but they’re smart readers *cough* *suckup* *cough*. Except for those who find this site by Google and are not searching for a technical topic. Them are the dumbest f***s I’ve ever seen.

Well stick around, I have an exciting line-up of topics coming up. They actually involve a bit of work *damn!*, so they’ll be out less frequently. But they will be above poor. I’ll probably try to blatantly start a controversy or two to drum up traffic so that people will click on my ads (oops, I’m not supposed to promote the ads, there’s controversy #1) and this blog can pay for itself. And you can be sure I’ll continue to be one vain motherblogger.