Archive for the ‘.NET Programming’ Category

Getting CC.Net working on our Test/Dev/Staging box

without comments

I used Jeff Atwoods article on Setting up Subversion on Windows to get started.

Once Subversion was up and running, I installed TortoiseSVN to create a repository, VisualSVN to connect to a repository and begun the CI installation.

Install Cruise Control on the Server and install as service
Configure the ccnet.config with a Project proj1
Create a working directory
In the working directory\bin directory, install nant, nantcontrib, visualsvn
Create a project directory in the working directory
proj1
In the proj1 directory, create a nant build script
Start the Cruise Control service

Key is to get the config file correct. There’s lots of posts on getting CI working so this is just some brief notes.

Written by grantmcinnes

April 13th, 2010 at 9:08 am

log4net example

without comments

 

In a recent project, I needed to implement logging and decided to use the log4net.dll which I have seen referenced in a number of different open source projects. Here are the steps I had to taken in order to use log4net in my project:

 

1. Download the log4net.dll from http://sourceforge.net/projects/log4net/

2. Add a reference to your project that includes the downloaded log4net.dll

3. Add a log4net section to your web.config/app.config file:

<configuration>
    <configSections>
            <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
        </sectionGroup>
    </configSections>
</configuration>

4. Add a log4net.config file to your project with the following configuration:

<?xml version="1.0" encoding="utf-8"?>
<log4net debug="true">
  <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
    <param name="File" value="log4netoutput.log" />
    <param name="AppendToFile" value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%d [%t] %-5p [%c] %m%n" />
    </layout>
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="LogFileAppender" />
  </root>
</log4net>

There are various Appenders you can create but this example uses a text file to log the results into the bin directory of the application. There are also different values that can be used as part of the ConversionPattern to get different output.

5. Be sure to change the properties of the log4net.config file in your project for the Copy to Output Directory attribute to Copy Always. I spent hours debugging my code because the config file was not being copied into the bin directory and log4net did not throw any exceptions. Since I had not used log4net before, I was making the assumption the problem was with my code and/or config file settings.

6. Here’s my code from a test method to make sure log4net is working correctly:

[Test]
public void TestLog4NetOnItsOwn()
{
    ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    XmlConfigurator.Configure(new FileInfo(Settings.Default.log4net_config_file)); 
    logger.Debug("Here is a debug log.");
}

To log results to the console, include the following line of code:

BasicConfigurator.Configure();

 

I’ve seen other posts that reference the log4net.config file in the Assembly.cs file rather than in code:

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

 

Other Posts and Resources:

http://it.toolbox.com/blogs/daniel-at-work/using-log4net-in-cnet-26794

http://geekswithblogs.net/bsherwin/archive/2008/02/15/119657.aspx

Written by grantmcinnes

June 25th, 2009 at 2:45 pm

Posted in .NET Programming

How to Open an MVC project in Visual Studio 2010

without comments

Written by grantmcinnes

June 9th, 2009 at 11:25 am

Posted in .NET Programming

Regular Expressions Cheat Sheet (V2)

without comments

Written by grantmcinnes

May 20th, 2009 at 3:55 pm

Posted in .NET Programming

Eric Hexter’s Current .NET Application and Tooling Stack

without comments

Written by grantmcinnes

May 20th, 2009 at 3:01 pm

Posted in .NET Programming

WCF Service Project configuration for https

without comments

Rowan has spent alot of time on WCF and has a good understanding of WCF services. In this example, I wanted to host a WCF service on a website and use it with https. Below is the configuration necessary to do that.

In web.config file create the serviceBehaviors, bindings, and services section:

 

<system.serviceModel>

<behaviors>

<serviceBehaviors>

<behavior name="MembershipProviderHelperBehavior">

<serviceMetadata httpsGetEnabled="true" httpsGetUrl="" />

<serviceDebug includeExceptionDetailInFaults="false" />

</behavior>

</serviceBehaviors>

</behaviors>

<bindings>

<basicHttpBinding>

<binding name="TheConfig">

<security mode="Transport"/>

</binding>

</basicHttpBinding>

</bindings>

<services>

<service behaviorConfiguration="CustomClassHelperBehavior" name="CustomClassHelper">

<host>

<baseAddresses>

<add baseAddress="https://ssl.texmed.org/Services/CustomClassHelper" />

</baseAddresses>

</host>

<endpoint address="" binding="basicHttpBinding" contract="ICustomClassHelper" bindingConfiguration="TheConfig">

</endpoint>

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />

</service>

</services>

</system.serviceModel>

Written by grantmcinnes

April 24th, 2009 at 1:57 pm

Posted in .NET Programming

Remove and Add handler programmatically in C#

without comments

 

this.ControlName.PropertyChanged -= new PropertyChangedEventHandler(ControlName_PropertyChanged);

this.ControlName.PropertyChanged += new PropertyChangedEventHandler(ControlName_PropertyChanged);

Written by grantmcinnes

April 8th, 2009 at 9:42 am

Posted in .NET Programming

Getting Silverlight Tools Installed on VS2008

without comments

 

Uninstall Silverlight and any other Silverlight references. It seems like there is an entry added into Add/Remove Programs even if the installer fails.

I then used this article to get Silverlight installed:

http://timheuer.com/blog/archive/2008/09/29/install-silverlight-2-rc0-offline.aspx

Written by grantmcinnes

March 16th, 2009 at 10:55 am

Posted in .NET Programming

Getting Vault to run on a 64bit machine with VS2003

without comments

 

1. Add the following keys:

[HKEY_LOCAL_MACHINE\SOFTWARE\SourceCodeControlProvider]
"ProviderRegKey"="SOFTWARE\\SourceGear\\Vault Client"

[HKEY_LOCAL_MACHINE\SOFTWARE\SourceCodeControlProvider\InstalledSCCProviders]
"SourceGear Vault VS2003 Compatible Client"="SOFTWARE\\SourceGear\\Vault Client"

[HKEY_LOCAL_MACHINE\SOFTWARE\SourceGear]

[HKEY_LOCAL_MACHINE\SOFTWARE\SourceGear\SourceGear Vault Client]
"InstallDir"="C:\\Program Files (x86)\\SourceGear\\Vault Client\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\SourceGear\Vault Client]
"InstallDir"="C:\\Program Files (x86)\\SourceGear\\Vault Client\\"
"SCCServerName"="SourceGear Vault Classic Client"
"SCCServerPath"="C:\\Program Files (x86)\\SourceGear\\Vault Client\\VS2003_Client\\VaultIDE.dll"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SourceCodeControlProvider]
"ProviderRegKey"="SOFTWARE\\SourceGear\\Vault Client"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SourceCodeControlProvider\InstalledSCCProviders]
"SourceGear Vault VS2003 Compatible Client"="SOFTWARE\\SourceGear\\Vault Client"

2. Restart Visual Studio and check the Source Control item Under Tools\Options

Written by grantmcinnes

March 11th, 2009 at 1:04 pm

Posted in .NET Programming