Monthly Archives: May 2015

GoSimple.Logging.Log4Net

Wouldn’t it be great if I ‘had a central place where I could keep and work on all my little nuggets of utility code I’ve written over the years. Also be able to download them from nuget would be very convenient. This is why I’ve decided to setup a new project on Github. There I just posted the first library of my personal Swiss army knife framework.

These libraries where primarily designed to build loosely-coupled applications where you can swap out particular components without affecting the rest of the application. Most of my libraries are just small layers above existing frameworks providing a common API that simplify their usage (for me at least). The libraries ease the use of these frameworks by providing standard configurations and exposing only the functionalities I found useful for me through what I saw as a “common API”.

The first library I uploaded is: Go.Simple.Logging

GoSimple.Logging is a small and simple library that provides a common interface for logging. It comes together with an implementation for Log4Net: GoSimple.Logging.Log4Net.

It provides a simple logging interface (Logger.Debug(..), Logger.info(..), Logger.warn(…), Logger.Error(…),….).  I use this nuget package in all my projects to easily integrate with Log4Net without having to remember how to configuer & setup Log4Net.

The library comes with an appender to send the logs through syslog to a Splunk server. The TcpSyslogAppender you’ll find in the Log4Net implementation was extensively tested and fine-tuned on many large scale applications running in production.

You can download it through nugget by using the nugget console:

Install-Package GoSimple.Logging.Log4Net

The most valuable extensions you’ll find in this project are:

  • Syslog Appender: used to send your logs over TCP or UDP to a syslog server like Splunk, Logstach or Kiwi.
  • Rolling File Appender: when GoSimple rolls a log file, it saves and closes the old file and starts a new file.

GoSimple.Logging comes with a sample project, you’ll find it on the github project home. It provides an example of how to configure your application for GoSimple.Logging in just one line of code. You’ll also find a sample Log4Net config file with example config sections for each appender.

To enable it on your project you need to :

  • 1) Review the Log4Net.config file on the application root.
  • 2) In VS set the property “Copy to output directory” of the Log4Net.config file to “Copy always”
  • 3) In your application entry point (bootstrapper/main) initialize the Logger:
    Logger.Initialize(new Log4NetLogger());

Voilà that’s all you need to configure to enable logging in your application.

How to prevent powershell long content to be truncated with three dots.

Powershell sometimes truncate large strings with three dots ()

PS C:\> Get-MyServers
{GFMPRD02, GFMPRD04, GFMPRD06, GFMPRD08…}
Even when using the Format-Table command and setting the length via the width property is not always a solution especially when you want to export the result to a CSV format, you can’t use the ft command.
The simplest solution I found is:
to set the variable $FormatEnumerationLimit to -1
PS C:\> $FormatEnumerationLimit =-1
PS C:\> Get-MyServers
{GFMPRD02, GFMPRD04, GFMPRD06, GFMPRD08, GFMPRD09}

How to enable “Open Developer command prompt here” in Windows Explorer

In Windows Explorer you can open a command prompt from any directory by Shift-Right-Click on any directory.

You can make that command prompt behavie like the Visual Studio Command Prompt (and have access to all usual developer utilities like tf.exe, sn.exe etc …).

Create file D:\Projects\DevCmd.bat :

@echo off
pushd “%1”
title Developer Command Prompt
call “C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat”

Merge into your registry the following .reg file

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
@=”cmd /s /k d:\\projects\\devcmd.bat \”%V\””

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmd\command]
@=”cmd /s /k d:\\projects\\devcmd.bat \”%V\””

[HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
@=”cmd /s /k d:\\projects\\devcmd.bat \”%V\””

Log off, log on and you are good to go

Windows Integrated authentication keeps on giving 401 status code

Some website require custom hosting configuration even when developing locally. For example if you need to enable ssl. If you use a separate host name for you locally hosted website, you may encounter Windows Authentication issues because Kerberos/NTLM ensures the symbolic name of the website does not resolve to the loopback address (127.x.x.x).

The behavior with IE is you get prompted for your username/password repeatedly.

To resolve the issue you may follow Method 1 in the following article : https://support.microsoft.com/en-us/kb/896861

Method 1: Specify host names (Preferred method if NTLM authentication is desired)
To specify the host names that are mapped to the loopback address and can connect to Web sites on your computer, follow these steps:1.Set the
DisableStrictNameChecking
registry entry to 1. For more information about how to do this, click the following article number to view the article in the Microsoft Knowledge Base:
281308 Connecting to SMB share on a Windows 2000-based computer or a Windows Server 2003-based computer may not work with an alias name

2.Click Start, click Run, type regedit, and then click OK.
3.In Registry Editor, locate and then click the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0

4.Right-click MSV1_0, point to New, and then click Multi-String Value.
5.Type BackConnectionHostNames, and then press ENTER.
6.Right-click BackConnectionHostNames, and then click Modify.
7.In the Value data box, type the host name or the host names for the sites that are on the local computer, and then click OK.
8.Quit Registry Editor, and then restart the IISAdmin service.

BackConnectionHostNames should list the names of the host names used for local deployment