By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,052 Members | 1,551 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,052 IT Pros & Developers. It's quick & easy.

formatting problem

P: n/a
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

Sep 30 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a

gopal wrote:
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/

Sep 30 '06 #2

P: n/a
Nick

Thats Excellent.. Nice Day..
nick_nw wrote:
gopal wrote:
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/
Sep 30 '06 #3

P: n/a
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

gopal wrote:
Nick

Thats Excellent.. Nice Day..
nick_nw wrote:
gopal wrote:
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/
Sep 30 '06 #4

P: n/a
What is the problem? You get exactly the formatting that you specify. If
you don't like the formatting, change it.

gopal wrote:
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

gopal wrote:
>Nick

Thats Excellent.. Nice Day..
nick_nw wrote:
>>gopal wrote:
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/
Sep 30 '06 #5

P: n/a
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


Göran Andersson wrote:
What is the problem? You get exactly the formatting that you specify. If
you don't like the formatting, change it.

gopal wrote:
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

gopal wrote:
Nick

Thats Excellent.. Nice Day..
nick_nw wrote:
gopal wrote:
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 irritatingto
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/
Sep 30 '06 #6

P: n/a
Of course you can. Why wouldn't you?

gopal wrote:
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


Göran Andersson wrote:
>What is the problem? You get exactly the formatting that you specify. If
you don't like the formatting, change it.

gopal wrote:
>>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

gopal wrote:
Nick

Thats Excellent.. Nice Day..
nick_nw wrote:
gopal wrote:
>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/
Sep 30 '06 #7

P: n/a
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
Göran Andersson wrote:
Of course you can. Why wouldn't you?

gopal wrote:
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


Göran Andersson wrote:
What is the problem? You get exactly the formatting that you specify. If
you don't like the formatting, change it.

gopal wrote:
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

gopal wrote:
Nick

Thats Excellent.. Nice Day..
nick_nw wrote:
gopal wrote:
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/
Oct 1 '06 #8

P: n/a
Put the formatting string in a constant, and use the constant in the
formatting statements.

gopal wrote:
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
Göran Andersson wrote:
>Of course you can. Why wouldn't you?

gopal wrote:
>>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


Göran Andersson wrote:
What is the problem? You get exactly the formatting that you specify. If
you don't like the formatting, change it.

gopal wrote:
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
>
gopal wrote:
>Nick
>>
>Thats Excellent.. Nice Day..
>>
>>
>nick_nw wrote:
>>gopal wrote:
>>>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/
Oct 3 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.