Home OFC Tech (blog)

OFC Tech (Strategy & Technology Blog)

Configure Log4Net with NUnit

E-mail Print
The Problem:

When you use the NUnit grapical interface to run unit tests, it short circuits the output from log4net.  This happens because NUnit itself is using log4net, and by default it turns the log outputs off.  The end result of this is that you go through all this trouble to get log4net working correctly, and your log entries mysteriously fail to show up when you run the unit tests.  This affect both console logging, and logging to files.

 

The resolution:

There is definitely some information out there, but most of what I found was a touch cryptic.  The purpose of this entry is share a plain English way of working around this problem.

 

Step 1: Add an application config file and rename it to something like "Test.config".  Don't be hard headed like me and ask "Why do I need to rename this file".  Just do it and make sure that the config file you add has the appropriate build action set so it gets copied to the bin directory as content.

Nunit_testconfig

 

Step 2: Add your log4net configuration entry to the "Test.config" file.  If you're reading this article, you should already know how to do this.  But if you don't, please refer to the log4net setup documentation.

 

Step 3: Add code to your unit test project to configure log4net at runtime (i.e. after the NUnit GUI has messed with the configuration).  The code snippet below does it in the constructor of one of my test classes.  This has the obviously limitation of only firing our configuration code once a test in this particular class is fired.  Optional: If you want a more global version of this approach that applies to all of your tests classes, embed the runtime log4net configuration in a class marked as being a [SetupFixture] instead of placing in an actual test class.

 

[TestFixture]
public class LoggingTests
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public LoggingTests()
{
FileInfo fileInfo = new FileInfo(@"C:\MOHQ\Middleware\UnitTests\bin\Debug\Test.config");
log4net.Config.XmlConfigurator.Configure(fileInfo);
}

[Test]
public void BasicLogTest()
{
log.Error("Hmm, Write my log entry already");
}

[Test]
public void DatabaseLogTest()
{

}
}

 

At this point your done.  Any log4net entries you have configured should now show up in the appropriate logs.

Add a comment
Last Updated ( Monday, 05 April 2010 14:55 )
 

WPF Shader Effects - Part I

E-mail Print

This article is kind of "Shader Effects for Dummies".  Or maybe more appropriately, "Shader Effects for people who don't really know **** about WPF".  So with that out of the way, here goes...

I got started by watching this video on YouTube that shows off a ton of custom transition effects for WPF.  If you'd like to incorporate some of these effects into one of your own WPF applications, there are a few gotchas that you are expected to figure out on your own.


  • Gotcha 1: You have to download the effect library source from Codeplex and compile the binaries yourself.  The source can be found here.
  • Gotcha 1a: The source on Codeplex won't compile cleanly. I had to make a code fix to line 38 of the Ripple.fx file in the effects library.  I changed: float falloff = saturate(1-distance); to: float falloff = 1-distance; per the screenshot below.

    Ripple
  • Gotcha 2: Once you add refererences to the shader effect libraries to your project, you have a whole new set of effects that you can choose from in Expression Blend.

    Effects

  • Gotcha 3: You really *really* should get comfortable with creating animations and using the built in render transform functionality in Expression Blend before trying to tackle your own programatic implementation of the Shader Effects library for the first time.  This is just my opinion, but once you see the XAML getting output as you add things to the Blend timeline, its much easier to concepualize your own implementation.  This video on YouTube is a provides a pretty clear explanation of what render trasformations do for you with WPF.

 


Stay tuned for part 2 of this series where I run through a couple examples of how to implement simple transitions programmatically.

Add a comment
Last Updated ( Friday, 19 March 2010 02:41 )
 

Install SmarterStats on IIS7

E-mail Print

The Problem:

After completing the installation of SmarterStats (A web analytics package from SmarterTools Inc.) on Windows Server 2008 / IIS7, you are unable to login in when accessing the site through the IIS7.  Attempting to log in with the correct credentials results in an error message indicating that the site/user/pass is invalid.  This problem persists even though you follow the supplied installation instructions to the letter.

SmarterStats

In my case I was able to log in perfectly fine when I accessed the site via SmarterStats built in web service, but not when I attempted the host the site through IIS.  The other thing that really threw me is the fact that I had done this installation over a dozen times on IIS6/Win2k3 without any sort of hitch whatsoever.

The Resolution:

SmarterStats needs to be able to write it's configuration data at: "C:\Program Files\SmarterTools\SmarterStats\MRS\App_Data".  On Windows Server 2003, this just works, no tweaking required.  On Windows Server 2008, attempted writes to this path fail unless you take some specific actions. (They exacerbate the problem by masking the exception that gets generated and making it look like an invalid credential)

What causes this is a key difference between IIS6 application pools and IIS7 application pools (on a Windows 2008 server).  In IIS6, app pools have a default identity of "Network Service".  On Windows 2008 they have a default identity of "ApplicationPoolIdentity".  The fix is to manually change the identity of the application pool that SmarterStats is running in to "Network Service", and give "Network Service" modify permissions on the App_Data folder. Once you've done that you should be able to log in normally.

Add a comment
Last Updated ( Saturday, 13 March 2010 15:29 )
 

asp.netPRO Reader's Choice Awards 2009

E-mail Print

For whatever reason, it's actually pretty difficult to find a "coherent" list of these results.  There are several .NET component vendors that make mention of the categories that they won, but (for obvious reasons) they typically don't mention the runners up, etc.  At any rate, I've listed the results in a tabular format below.  These results were sourced from an entry on the magazine's blog which can be found here.

Categoy Winner Runner Up Honorable Mention
Add-In: Developer Express CodeRush for Visual Studio .NET JetBrains' ReSharper Madinina Software's CodeObject for Visual Studio .NET
Charting and Graphics Tool: Developer Express XtraCharts Suite Telerik RadChart for ASP.NET AJAX Dundas Chart for .NET
Chat Application: Xigla Software's Absolute Live Support .NET CuteSoft Components' Cute Chat Web Furbish's JaxterChat ASP.NET Chat Control
Code Editor: IDM Computer Solutions' UltraEdit Helios Software Solutions' TextPad SlickEdit Tools for Microsoft Visual Studio
Communications Tool: /n software's IP*Works! Dart Communications' PowerTCP for .NET Catalyst Development's SocketTools .NET Edition
Community Resource: DevExpress Community: Site/Developer Express The Code Project Microsoft's ASP.NET Site
Component Set: Developer Express DXperience ASP.NET Telerik RadControls for ASP.NET AJAX ComponentOne Studio Enterprise
Content Management System: Microsoft Office SharePoint Server 2007 - Web Content Management DotNetNuke Professional Edition Telerik Sitefinity CMS
e-Commerce Package: AbleCommerce Asp.Net Shopping Cart AspDotNetStorefront Corporate Web Solutions' .netCART
E-mail Control: 360 IMPACT's ASP.NET Auto Email Advanced Intellect's aspNetEmail /n software's IP*Works! S/MIME
Forum Application: Telligent Community Server BV Software's DotNetBB Forums Active Modules' Active Forums
Grid: Developer Express ASPxGridView Telerik RadGrid for ASP.NET AJAX FarPoint Spread for ASP.NET
Hosting Service: DiscountASP.NET Applied Innovations MaximumASP
IDE: Microsoft Visual Studio Delphi Prism Sun Microsystems' Sun Studio 8
Navigation Control: Developer Express ASPxNavBar Telerik RadMenu for ASP.NET AJAX ComponentOne Menu for ASP.NET
Online Editor: Developer Express ASPxHTML Editor Telerik RadEditor for ASP.NET AJAX Infragistics NetAdvantage for ASP.NET WebHtmlEditor
Polling Tool: CodeWidgets.com's Online Voting/Survey Web-App PeterBlum.com's Peter's Polling Package
Printing/Reporting Tool: Developer Express XtraReports Suite Telerik Reporting GrapeCity-data Dynamics' ActiveReports for .NET
Project Management/Defect Tracking: Axosoft's OnTime 2009 Fog Creek Software's FogBugz Seapine Software's TestTrack Pro
Scheduling/Calendar Tool: Developer Express ASPxScheduler Telerik RadScheduler for ASP.NET AJAX ComponentOne WebSchedule/WebCalendar
Security Tool: PreEmptive Solutions' Dotfuscator /n software's IP*Works! SSL Novalys's Visual Guard for .NET
Silverlight: Developer Express AgDataGrid Suite Telerik RadControls for Silverlight ComponentOne Studio for Silverlight
Testing/QA Tool: Telerik WebUI Test Studio (powered by ArtOfTest) Red Gate Software's ANTS Profiler AutomatedQA's TestComplete
Training: ASPSmith.com's ASP.NET Training Telerik Training AppDev Training
Utility: Developer Express ASPxSpellChecker Telerik RadSpell for ASP.NET AJAX CodeSmith Tools' CodeSmith

 

Add a comment
Last Updated ( Sunday, 24 January 2010 21:29 )
 

Flex uploads using ASP.NET

E-mail Print

I'm posting a quick writeup on using an Adobe Flex UI to upload a file using a .NET based post handler.  For whatever reason, most of the available documentation out there is a little spotty on this topic.  The article is written from the perspective of an individual with a considerable amount of ASP.NET subject matter expertise, but very little practical experience with Flex / Flash development.

The short version of this is that: The Flex upload client lets us specify a url that will process the upload.  That url can be a php page, jsp page, ASP.NET page, etc. In our example we're going to use an ASP.NET page handler.  Our ASP.NET worker page is really just a page stub with a code behind that pulls the submitted file out of the ASP.NET Request.Files collection and saves it to a path on the server.

The more detailed version with the relevant sections of code: We'll start by taking a look at the Flex UI client for all of this.  It's surprising simple.  Basically it's a few UI elements, some event handlers, and a parameter or two that will need to be set.  It's very similar in concept to doing a file upload with an html based form with a file browser control on it.  The only secret sauce in the example below is that I've restricted the upload types to images only, and I also limit the maximum file upload to 5MB.  Most of the real heavy lifting is done with our post handler.

Here's the entire .mxml file:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
backgroundColor="white"
creationComplete="init();">

<mx:Script>
<![CDATA[
// Includes
import mx.controls.Alert;

// Members
private var fileRef:FileReference;
private var fileFilter:FileFilter;
private var maxSize = 5120000;
private const FILE_UPLOAD_URL:String = "http://youserver.com/PostHandler.aspx";

private function init():void {

fileRef = new FileReference();
fileRef.addEventListener(Event.SELECT, fileRef_select);
fileRef.addEventListener(ProgressEvent.PROGRESS, fileRef_progress);
fileRef.addEventListener(Event.COMPLETE, fileRef_complete);

// create a FileFilter to limit file types
this.fileFilter = new FileFilter("Images", "*.png;*.jpg;*.gif;*.bmp");


}

private function browseAndUpload():void {

fileRef.browse([this.fileFilter]);
message.text = "";

}

private function fileRef_select(evt:Event):void {

try {

if (fileRef.size > maxSize)
{
Alert.show("File size cannot exceed 5MB", "File Selection Error");
}
else
{
message.text = "size (bytes): " + numberFormatter.format(fileRef.size);
fileRef.upload(new URLRequest(FILE_UPLOAD_URL));                    
}

} catch (err:Error) {
message.text = "ERROR: zero-byte file";
}
}

private function fileRef_progress(evt:ProgressEvent):void {

progressBar.visible = true;

}

private function fileRef_complete(evt:Event):void {

message.text += " (complete)";
progressBar.visible = false;

}

]]>
</mx:Script>

<mx:NumberFormatter id="numberFormatter" />

<mx:Button label="Upload file"
click="browseAndUpload();"  x="80" y="108"/>
<mx:Label id="message"  x="80" y="138"/>
<mx:ProgressBar id="progressBar"
indeterminate="true"
visible="false"  x="174" y="108"/>

</mx:Application>

Now that you've seen our flex client, lets move on to the worker page we're going to build in ASP.NET.  There are tons of example out there on how to process an ASP.NET file upload upon postback (i.e. using the .NET model of doing things).  This example is a little bit different in that it's not a postback, but rather a form submission to a completely separate page.  Which is kind of a throwback to the old classic ASP days.  Just to be 100% explicit about this, your worker page URL has to match what was specified in our Flex client (in our case that's http://youserver.com/PostHandler.aspx)

Our ASP.NET "worker" page is really just a webform that snags the file out of the Request.Files collected of HttpPostedFiles.

Take a look at the code (which I've just throw into the Page_Load Event):

protected void Page_Load(object sender, EventArgs e)
{

// Page should only respond to posted files
if (Request.Files.Keys.Count > 0)
{
foreach (string key in Request.Files.Keys)
{
// Block Level Variables
HttpPostedFile postedFile = Request.Files[key];

// FYI: Upload path is being pulled from application variable previously set in global.asax
string filePath = string.Format("{0}\\{1}", Application["UploadPath"].ToString(), System.IO.Path.GetFileName(postedFile.FileName));

// Save To Web Server
postedFile.SaveAs(filePath);
Response.Write("file uploaded");
}
}
else
{
throw new ApplicationException("No Files posted");
}

}

And there you have it.  The only thing you really need to watch out for is to make sure you are attempting to write your file to a folder on the server that the IIS_WPG group has access to.  And lasty, In my case I ultimately fleshed out the logic in the worker page to do a few more things beyond just handling the upload (store an index for the file in a database, etc.).

 

Add a comment
Last Updated ( Friday, 12 March 2010 01:06 )
 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  Next 
  •  End 
  • »
Page 1 of 2

Make a Payment

ID Card Printing

WorkForce ID cards are custom designed to reflect you unique business, brand or identity. Click to view our product brochure

WorkForceID_Marketing_v1.11

We also have specific offerings tailored to small businesses and individual entrepreneurs.


Certifications

Oracle Partner Logo

MS Partner Logo

Our Partners

The Gravely Group
INCREASE CDC
ECDI - Columbus
DMW Computers

Our Products

Sample imageNeighborhood Shield Drive
WorkForce ID
My Property Tag

Our Services

Application Development
Website Design
Flash Multimedia Design
Ecommerce & Storefronts
Card Printing & Plastics