473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Conditional Log messages

Hi,

My application requires 3 different types of logging:

Standard
Debug
Performance

I want an approach that can easily allow the user to do this:

At the moment, my code looks something like this:

//To display some standard log message
WriteLog( myMsg );

//To display a debug message
if( _debug )
{
WriteLog( myMsg );
}

//To display a performance message
if( _performance )
{
WriteLog( myMsg );
}

This bloats the code a little.

The other approach is to have a wrapper call for each.
For debug:

public void DebugMessage( string msg )
{
if( _debug )
{
WriteLog( myMsg );
}
}

Disadvantage is the code would always call the wrapper function, even if
_debug is false.

So, I am looking for a solution to this problem which reduces the amount
of of times _debug and _performance is used,
but does not have lots of redundant method calls.

Any ideas?

Using soemthing like #DEBUG is not an option either, since the logging
is configurable.

Thanks in advance for the help.

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Jan 22 '07 #1
3 1521
"Steven Blair" <st**********@btinternet.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Any ideas?

Using soemthing like #DEBUG is not an option either, since the logging
is configurable.

Thanks in advance for the help.
Use Log4Net?
http://logging.apache.org/log4net/
Jan 22 '07 #2
I have a log library which needs to be used.
The problem is when it's used.

*** Sent via Developersdex http://www.developersdex.com ***
Jan 22 '07 #3
Hi,

I would do something like your second option (create a method) but I would
have the same method no matter the source of the debugging.

Inside the method you could check for the status of the particular debugging
and simply ignore it or log it.
Of course this has some overhead but no matter what you do the overhead will
be present in one way or other.

You could do like:

void Log( string msg, DebugInfoType debugType)
{
switch ) debugType:
case Standard:
////
case Debug
if ( _debug )

}
--
Ignacio Machin
machin AT laceupsolutions com
"Steven Blair" <st**********@btinternet.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
| Hi,
|
| My application requires 3 different types of logging:
|
| Standard
| Debug
| Performance
|
| I want an approach that can easily allow the user to do this:
|
| At the moment, my code looks something like this:
|
| //To display some standard log message
| WriteLog( myMsg );
|
| //To display a debug message
| if( _debug )
| {
| WriteLog( myMsg );
| }
|
| //To display a performance message
| if( _performance )
| {
| WriteLog( myMsg );
| }
|
| This bloats the code a little.
|
| The other approach is to have a wrapper call for each.
| For debug:
|
| public void DebugMessage( string msg )
| {
| if( _debug )
| {
| WriteLog( myMsg );
| }
| }
|
| Disadvantage is the code would always call the wrapper function, even if
| _debug is false.
|
| So, I am looking for a solution to this problem which reduces the amount
| of of times _debug and _performance is used,
| but does not have lots of redundant method calls.
|
| Any ideas?
|
| Using soemthing like #DEBUG is not an option either, since the logging
| is configurable.
|
| Thanks in advance for the help.
|
| Steven
|
|
|
| *** Sent via Developersdex http://www.developersdex.com ***
Jan 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found...
62
by: Reinhold Birkenfeld | last post by:
Hi, after Guido's pronouncement yesterday, in one of the next versions of Python there will be a conditional expression with the following syntax: X if C else Y which is the same as today's...
3
by: David Link | last post by:
Hi All, Here's a Conditional drop_table func for those interested. There was a thread on this a long time back. We do this all the time : DELETE TABLE sales; CREATE TABLE sales (...);
4
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
1
by: ammarton | last post by:
Hello all...I'm a bit new to working with Macros in Access so forgive me if the terminology I use is not accurate. To preface this, basically I am using a form on a replicated database so the...
10
by: John Smith | last post by:
After reading C# documentation the Conditional attribute seemed the way to go, but after inspecting the IL it seems those methods are still there and I imagine the CLR removes them. Using #if DEBUG...
14
by: gupta.keshav | last post by:
Hi, I want to know the trick of implementing condition operator or (if()... else...). Symbols to use: ~, !, ^,&, +, |, <<, >>. NOt to use: if statement, loops,
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
3
by: naunetr | last post by:
hello all, i wrote the small program below to practice conditional compiling. if i define MYSYMBOL then everthing works fine, but when i comment MYSYMBOL gcc gives the following message:...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.