Page 1 of 1

how to write log using c#

Posted: Tue Feb 03, 2015 11:52 am
by prasanna
hi,
how to write log in a particular location using c#

Re: how to write log using c#

Posted: Tue Feb 03, 2015 12:53 pm
by CookieMonster
Hi Prasanna,

Could you please give more details about which log you want to use.
The Ranorex result log, or the NLog framework?

Regards
Dan

Re: how to write log using c#

Posted: Tue Feb 03, 2015 1:35 pm
by prasanna
Could you please explain about NLog framework

Re: how to write log using c#

Posted: Tue Feb 03, 2015 4:35 pm
by CookieMonster
Hi Prasanna,
  • 1. Create a Ranorex Solution

    2. In the recording on the user code file you create a method.

    3. Add the Ranorex.Libs. Or Download NLog.
    If you use the class LoggerFactory, then you will get the Ranorex internal use only message, and you will be advised that have to add Ranorex.Libs. to your project.

    4. If you add the reference over the LoggerFactory, you can delete this code line.

    5. Add this lines to into the code :)
    https://github.com/nlog/NLog/wiki/Configuration-API

    6. Now on your output directory a file.txt will be created. After build and running.
If you want to store your log file somewhere else, may you can do it somehow with these code lines. But I haven't tried it.

Code: Select all

FileTarget target = LogManager.Configuration.FindTargetByName(targetName) as FileTarget;
target.FileName = filename;
But by the way, why are you not using the Ranorex Report instated of using NLog?

Cheers
Dan

Re: how to write log using c#

Posted: Wed Feb 04, 2015 6:07 am
by prasanna
I used Report.Log it is just showing the message in report so i asked about NLog framework.

Re: how to write log using c#

Posted: Wed Feb 04, 2015 3:10 pm
by krstcs
I think the question was more about WHY you aren't using the Ranorex Report logging mechanism.

So, why do you feel the Ranorex Report is not acceptable, in your case, for logging information?

Is there something that you are having trouble with in the Ranorex Report?


I've found that it is very versatile and easy to work with for all the logging I do.