formatting problem

  • Thread starter Thread starter gopal
  • Start date Start date
G

gopal

Hi

I am trying to write to log file but the formatting of string is not
properly aligned in log file result

The results looks some thing like this

OK move.xml Successful
OK AppUser_ifrUsers.asp Successful

Here i have hardcoded OK & Successfull but the file name "move.XML" and
"AppUser_ifrUsers.asp" are obtained at when application is running.
The format expected is

OK move.xml Successful
OK AppUser_ifrUsers.asp Successful

Please can some one help me out regarding this..Its a bit irritating to
get like this


Thanks & Regards
Gopal
 
gopal said:
Hi

I am trying to write to log file but the formatting of string is not
properly aligned in log file result

The results looks some thing like this

OK move.xml Successful
OK AppUser_ifrUsers.asp Successful

Here i have hardcoded OK & Successfull but the file name "move.XML" and
"AppUser_ifrUsers.asp" are obtained at when application is running.
The format expected is

OK move.xml Successful
OK AppUser_ifrUsers.asp Successful

Please can some one help me out regarding this..Its a bit irritating to
get like this


Thanks & Regards
Gopal

There are a few ways to do this, one way (just waking up so someone
jump in if there is a more elegant solution) could be:


private string LogLine (string logEntry)
{
string OK = "OK";
string SUCCESSFUL = "Successful";
string line = String.Format ("{0} {1, -30} {2}", OK, logEntry,
SUCCESSFUL);

return line;
}

Example call:

string line = LogLine ("Test log entry");

The format specifier {1, -30} will pad the second string (logEntry)
with 30 characters.

On my blog I link to thiis excellent summary of string formatters:

http://idunno.org/displayBlog.aspx/2004071401

Best,

Nick
http://seecharp.blogspot.com/
 
Nick

Thats Excellent.. Nice Day..


nick_nw said:
There are a few ways to do this, one way (just waking up so someone
jump in if there is a more elegant solution) could be:


private string LogLine (string logEntry)
{
string OK = "OK";
string SUCCESSFUL = "Successful";
string line = String.Format ("{0} {1, -30} {2}", OK, logEntry,
SUCCESSFUL);

return line;
}

Example call:

string line = LogLine ("Test log entry");

The format specifier {1, -30} will pad the second string (logEntry)
with 30 characters.

On my blog I link to thiis excellent summary of string formatters:

http://idunno.org/displayBlog.aspx/2004071401

Best,

Nick
http://seecharp.blogspot.com/
 
Hi Nick

The proble has been solved except for the issue that wherever i am
using this format, i keep changing the alignment wherever i am loggin
the contants

Example at one place i am calling


strLogContent = String.Format ("{0,-22} {1, -30} {2}", STR_FAILED,
strMoveXMLFileName,
STR_LOG_FAILED);


At another place i am calling the with different alignment as

strLogContent = String.Format ("{0,-20} {1, -35} {2}", STR_FAILED,
strMoveXMLFileName,
STR_LOG_FAILED);


So should i then keep changin the alignment or can we have fixed
alignment.

I would really appreciate if you can help me solve this issue

Regards
JP
 
What is the problem? You get exactly the formatting that you specify. If
you don't like the formatting, change it.
 
I want the formatting to be same for all the Log file i am goin to list

Example

OK move.xml Successful ----
alignment/formatting is different
Failed AppUser_ifrUsers.asp Successful ----- align/formating
is different

Can t i have the same format/alignment at all places where i am logging
to file
 
Of course you can. Why wouldn't you?
I want the formatting to be same for all the Log file i am goin to list

Example

OK move.xml Successful ----
alignment/formatting is different
Failed AppUser_ifrUsers.asp Successful ----- align/formating
is different

Can t i have the same format/alignment at all places where i am logging
to file
 
Hi,

Please can you show/help me how sane alignment/format can be
used/applied for writing the log files. Would really apprecuate this.

Regards
JP
 
Put the formatting string in a constant, and use the constant in the
formatting statements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top