Saturday, May 13, 2006

Custom Trace Listern for EntLib

why reinvent the wheel and create this custom trace listner?
the current custom trace listerner in the documentation uses debug .write, which doesn't work in the "release" mode.
I would like to show trace message to debugview even in release mode.
OutputDebugString do the magic, see the code below


----
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;


namespace TareqCo.Framework.Logging
{
[ConfigurationElementType(typeof(CustomTraceListenerData))]
public class DebugTraceListener:Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.CustomTraceListener
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern void OutputDebugStringA(string message);

public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
{
if (data is LogEntry && this.Formatter != null)
{
this.WriteLine(this.Formatter.Format(data as LogEntry));
}
else
{
this.WriteLine(data.ToString());
}
}

public override void Write(string message)
{
OutputDebugStringA(message);
}

public override void WriteLine(string message)
{
OutputDebugStringA(message);
}

}
}

Friday, January 21, 2005


 Posted by Hello

Thursday, January 20, 2005


Imran Office :D Posted by Hello

 Posted by Hello

 Posted by Hello

:)  Posted by Hello

metal man, my friend Posted by Hello

happy :D Posted by Hello

 Posted by Hello

taking photo for myself :D Posted by Hello

 Posted by Hello

act  Posted by Hello

My indian Friend AD :D, in the middle, :D Posted by Hello

my friends at macrocell Posted by Hello

Per, Norway :) Posted by Hello

the most hard worker, I ever see, our CEO (Macrocell) Posted by Hello

Imran, My friend at UAE Posted by Hello

Nile at Night Posted by Hello

after eating :D Posted by Hello

Al Saray break fast Posted by Hello

 Posted by Hello

 Posted by Hello

Dream Park Posted by Hello

thinking Posted by Hello

Posted by Hello

Saturday, January 15, 2005


my brother Khalid Posted by Hello