Tuesday, September 20, 2011

So my test is on its way

I have been commissioned to write a distributed Backup service system. basically we’re talking about a Server element and multiple Services each polled by the server or polling the server – I have yet to decide that.

Each Service element will be able to backup a server and communicate back to the main Server element about its success or failure.

The server will then commission all the backup up data and get it to the main location.

the server will create a log detailing each services state : success/failure.

In step 2, there will be a GUI

Step 1, Design the Backup service element

 

For Now I have the Service element which I named BackupUtility

It asks a Factory for the right BackupEngine (I called it BackupWorker) and using IBackupWorker I manipulate it.

I Took newkie’s code from code-project (love that site btw) ThreadBase<T>.

He wrote two implementations, and using some knowhow I transformed it into a cancalable version I decided I don’t need, and reverted back. YEAY Sad smile

So now I wrote a class that implements it and adds logging to the start and finish and has some more fun parts. and a Factory to retrieve it. – had a heck of a time with log4net not reading its configuration file. – I wish log4net could just say HEY COUNLDNT FIND CONFIG FILE instead of spewing garbage when in debug mode – ooof

 

Next is the Parser

as the Workers are Threads and run asynchronously, 

As a worker threads are run asynchronously, the log files are also very jumbled up.  I have two options:

1) create two log files

2) parse/ sort the single log file

I’m guessing I’ll go with 1 because I think I wont know how many log files there will be until runtime. and I plan to use some version of DataTable to store my data. <this will also help in part two which is the WCF service and data transfers>

 

I have found a Microsoft Tool called Log Parser, so it’s a dandy

checking it out now

Monday, September 19, 2011

Log4Net Patterns

 

taken from http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html

The recognized conversion pattern names are:

a - Equivalent to appdomain - Used to output the friendly name of the AppDomain where the logging event was generated.

c - Equivalent to logger

C - Equivalent to type

class - Equivalent to type

d - Equivalent to date

enclosed between braces. For example, %date{HH:mm:ss,fff} or %date{dd MMM yyyy HH:mm:ss,fff}. If no date format specifier is given then ISO8601 format is assumed (Iso8601DateFormatter).

For better results it is recommended to use the log4net date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying AbsoluteTimeDateFormatter, DateTimeDateFormatter and respectively Iso8601DateFormatter. For example, %date{ISO8601} or %date{ABSOLUTE}.

These dedicated date formatters perform significantly better than ToString.

exception - Used to output the exception passed in with the log message.

If an exception object is stored in the logging event it will be rendered into the pattern output with a trailing newline. If there is no exception then nothing will be output and no trailing newline will be appended. It is typical to put a newline before the exception and to have the exception as the last data in the pattern.

F - Equivalent to file Used to output the file name where the logging request was issued.

WARNING Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue.

See the note below on the availability of caller location information.

identity - Used to output the user name for the currently active user (Principal.Identity.Name).

WARNING Generating caller information is extremely slow. Its use should be avoided unless execution speed is not an issue.

l - Equivalent to location

L - Equivalent to line

location

Used to output location information of the caller which generated the logging event.

The location information depends on the CLI implementation but usually consists of the fully qualified name of the calling method followed by the callers source the file name and line number between parentheses.

The location information can be very useful. However, its generation is extremely slow. Its use should be avoided unless execution speed is not an issue.

See the note below on the availability of caller location information.

level - Used to output the level of the logging event.

line - Used to output the line number from where the logging request was issued.

WARNING Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue.

See the note below on the availability of caller location information.

logger - Used to output the logger of the logging event. The logger conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets.

If a precision specifier is given, then only the corresponding number of right most components of the logger name will be printed. By default the logger name is printed in full.

For example, for the logger name "a.b.c" the pattern %logger{2} will output "b.c".

m - Equivalent to message

M - Equivalent to method

message - Used to output the application supplied message associated with the logging event.

mdc - The MDC (old name for the ThreadContext.Properties) is now part of the combined event properties. This pattern is supported for compatibility but is equivalent to property.

method - Used to output the method name where the logging request was issued.

WARNING Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue.

See the note below on the availability of caller location information.

n - Equivalent to newline

Outputs the platform dependent line separator character or characters.

This conversion pattern offers the same performance as using non-portable line separator strings such as "\n", or "\r\n". Thus, it is the preferred way of specifying a line separator.

ndc - Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event.

p - Equivalent to level

P - Equivalent to property

properties - Equivalent to property

property - Used to output the an event specific property. The key to lookup must be specified within braces and directly following the pattern specifier, e.g. %property{user} would include the value from the property that is keyed by the string 'user'. Each property value that is to be included in the log must be specified separately. Properties are added to events by loggers or appenders. By default the log4net:HostName property is set to the name of machine on which the event was originally logged.

If no key is specified, e.g. %property then all the keys and their values are printed in a comma separated list.

The properties of an event are combined from a number of different contexts. These are listed below in the order in which they are searched.

the event properties
The event has Properties that can be set. These properties are specific to this event only.
the thread properties
The Properties that are set on the current thread. These properties are shared by all events logged on this thread.
the global properties
The Properties that are set globally. These properties are shared by all the threads in the AppDomain.

r - Equivalent to timestamp

t - Equivalent to thread

timestamp

Used to output the number of milliseconds elapsed since the start of the application until the creation of the logging event.

thread

Used to output the name of the thread that generated the logging event. Uses the thread number if no name is available.

type

Used to output the fully qualified type name of the caller issuing the logging request. This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets.

If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. By default the class name is output in fully qualified form.

For example, for the class name "log4net.Layout.PatternLayout", the pattern %type{1} will output "PatternLayout".

WARNING Generating the caller class information is slow. Thus, its use should be avoided unless execution speed is not an issue.

See the note below on the availability of caller location information.

u - Equivalent to identity

username - Used to output the WindowsIdentity for the currently active user.

WARNING Generating caller WindowsIdentity information is extremely slow. Its use should be avoided unless execution speed is not an issue.

utcdate - Used to output the date of the logging event in universal time. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example, %utcdate{HH:mm:ss,fff} or %utcdate{dd MMM yyyy HH:mm:ss,fff}. If no date format specifier is given then ISO8601 format is assumed (Iso8601DateFormatter).

The date format specifier admits the same syntax as the time pattern string of the ToString.

For better results it is recommended to use the log4net date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying AbsoluteTimeDateFormatter, DateTimeDateFormatter and respectively Iso8601DateFormatter. For example, %utcdate{ISO8601} or %utcdate{ABSOLUTE}.

These dedicated date formatters perform significantly better than ToString.

w - Equivalent to username

x - Equivalent to ndc

X - Equivalent to mdc

% -The sequence %% outputs a single percent sign.

The single letter patterns are deprecated in favor of the longer more descriptive pattern names.

Sunday, September 18, 2011

UPDATED: Getting Log4Net to work with Dot.Net Framework 4.0

 

UPDATED: If you want to write code for Log4Net and you’re using dot.net 4 and it won’t compile do the following

open the src directory and open the log4net.csproj –> update it to dot.net 4

  1. Project Properties :
    1. Application : Target Framework : .Net Framework 4
      image
    2. Build : Conditional compilation symbols: change NET_1_0 to NET_4_0
      image
  2. AssemblyInfo.cs

Line 52: copy the line 52 and 53

and paste it under line 52

change #elseif(NET_1_0) to #elseif(NET_4_0)

and change Framework 1.0 to Framework 4.0

image

3. in References: Delete System.Data, System.Web references and add Reference : System.Data and System.Web from the .NET tab

*this is don’t so they are Framework 4 compatible (before they were Framework 1.1 compatible, which is not good enough for Framework 4.0 I guess.

Now change The SystemInfo CurrentThreadId from the Obsolete GetCurrentThreadId to the new System.Threading.Thread.CurrentThread.ManagedThreadId;

image

 

Next

Some security changes were made in the .NET 4.0 framework. In the AssemblyInfo.cs file of the log4net project, you'll find the following line:
[assembly: System.Security.AllowPartiallyTrustedCallers] –

This is affected by the security changes. Take a look at this page for more details: http://msdn.microsoft.com/en-us/library/system.security.allowpartiallytrustedcallersattribute.aspx.

because it’s bad for dot.net 4 , but not for anything else

add

image

 

Now Build using Release and all should work.

good luck