$$\newcommand{\eqdef}{\overset{def}{=}}$$

Tahir Hassan's Blog

My Technical Notes

Work Blog

Wednesday, 22 June 2016

Log4net: Simple Console Application that Uses MemoryAppender

This simple example uses log4net version 2.0.3 to write to a `MemoryAppender` which is the read to produce a string at the end of all the log messages.

Installing Log4net

We first download and install log4net version 2.0.3 using NuGet Package Manager Console:

Configuring Log4net via config file

We place the following configuration in our app/web.config file. It declares an appender called `MemoryAppender` which we will access through the C# code later. It also adds a config section under `configSections` so that log4net is configured.

Invoking Log4net's XML Configurator

Follow this post to invoke log4net's XML Configurator.

Converting Logs to a String

To get a string representation of all the logged statements, we use the following code. Note that the `result` variable will be set to the log data.

Log4net: Invoking XML Configuration

This can be done in two ways. We either add an assembly attribute:

or we invoke it through code:

Monday, 20 June 2016

XSD: Putting a MaxLength on a String element

Given a string element:

To turn it into a string with a max length of, say, `4000`, we turn it into:

If you wanted to define the restricted `simpleType` separately (let's say, for future changes), we could do:

and use it later in the file:

Emacs Regex Perculiarities

Given the input:

To turn them into properties such as:

We use `query-replace-regexp`, which accepts a search expression and then a replacement string. `\(.*\)` is our search expression. Emacs expects that we escape the bracket characters, even though they are a part of the regex,

is our replacement term. Notice the use of `\1` which is our input. This results in (notice the title-casing):

The title casing is the result of "case conversion", which can be turned off by using (stick in init?):

Friday, 17 June 2016

PowerShell: Add-Type for System.Xml.Linq DLL/namespace

To generate the `AssemblyName`, we can use C#:

Thursday, 16 June 2016

Creating a Git Repo on the Network From a GitHub Repo

You first `cd` to the network path, then you clone the GitHub repo to a "bare" repository:

Then you can `clone` this network repository into a working directory and then pull and push as usual.

Wednesday, 15 June 2016

Using DateTime.ToString to make string 12-hour Time String

`h` returns the hours in 12 hour format. For example `18` will return `6`. `mm` returns the minutes. `tt` returns `AM` or `PM`.