Logs(Log File) : General Questions

Logs(Log File)

Ask general questions here.

Logs(Log File)

Postby Praveen597 » Fri Sep 16, 2011 3:02 pm

Logs are very important for tracking the defects. We can know exactly where the code is failing to do our defined task.
Do we have any predefined methods for maintaining a log for all the actions done through code.
Or else, we manually need to write our own cod for logs.?

Any information on this is very helpful.

Thank you,
Praveen
Praveen597
 
Posts: 24
Joined: Sat Aug 27, 2011 10:41 am

Re: Logs(Log File)

Postby sdaly » Fri Sep 16, 2011 3:29 pm

See the Report class....

Here is a wee example, I use the .net StackTrace class so it outputs the class/method name too...

You can also do Report.Success(), Report.Failure(), Report.Warn(), Report.Debug etc...



Report.Setup(ReportLevel.Info, currentTestReportName, true);

LogInfo("information!!!");

Report.End();


public static void LogInfo(string info)
{
StackTrace stackTrace = new StackTrace();
string location = stackTrace.GetFrame(1).GetMethod().DeclaringType.Name + "::" + stackTrace.GetFrame(1).GetMethod().Name ;
Report.Info(location, info);
}
User avatar
sdaly
 
Posts: 213
Joined: Mon May 10, 2010 12:04 pm
Location: Dundee, Scotland

Re: Logs(Log File)

Postby omayer » Mon Sep 19, 2011 3:48 pm

Great Example .Thanks Scott
Tipu
omayer
 
Posts: 240
Joined: Thu Oct 28, 2010 7:14 pm

Re: Logs(Log File)

Postby Praveen597 » Tue Sep 20, 2011 1:20 pm

Thanks for your reply.


Can I have C # code please ...?
Praveen597
 
Posts: 24
Joined: Sat Aug 27, 2011 10:41 am

Re: Logs(Log File)

Postby sdaly » Tue Sep 20, 2011 1:23 pm

That is C# :?
User avatar
sdaly
 
Posts: 213
Joined: Mon May 10, 2010 12:04 pm
Location: Dundee, Scotland

Re: Logs(Log File)

Postby Praveen597 » Thu Sep 22, 2011 3:00 pm

"StackTrace stackTrace = new StackTrace();
string location = stackTrace.GetFrame(1).GetMethod().DeclaringType.Name + "::" + "

This one is not working with ranorex...!

Please help me out.
I am new for C#.
Praveen597
 
Posts: 24
Joined: Sat Aug 27, 2011 10:41 am

Re: Logs(Log File)

Postby Praveen597 » Thu Sep 22, 2011 3:52 pm

Hi Sdaly ,
It is working fine with;

System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();

Thank alot buddy. It completely my mistake to over look the code . Sorry for that.
And keep helping me..........!! :P
Praveen597
 
Posts: 24
Joined: Sat Aug 27, 2011 10:41 am

Re: Logs(Log File)

Postby sdaly » Thu Sep 22, 2011 6:27 pm

You could also bring that namespace into scope by adding -

Code: Select all
using System.Diagnostics


:mrgreen:
User avatar
sdaly
 
Posts: 213
Joined: Mon May 10, 2010 12:04 pm
Location: Dundee, Scotland

Re: Logs(Log File)

Postby omayer » Thu Sep 29, 2011 3:02 am

Where do I use this code on .cs file, like I am calling method enterEmailAddress(); should i use the below code before calling the method or any advise please.

Report.Setup(ReportLevel.Info, currentTestReportName, true);

LogInfo("information!!!");

Report.End();


public static void LogInfo(string info)
{
StackTrace stackTrace = new StackTrace();
string location = stackTrace.GetFrame(1).GetMethod().DeclaringType.Name + "::" + stackTrace.GetFrame(1).GetMethod().Name ;
Report.Info(location, info);
}
Tipu
omayer
 
Posts: 240
Joined: Thu Oct 28, 2010 7:14 pm


Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests