Help me start logging with C# Express 2005

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Help me start logging with C# Express 2005

lars2b
Hi,

I downloaded both the release and the last snapshot binaries, but didn't manage to get any log messages with C# Express edition 2005. What I did:
- added the references for NLog, NLog.DotNet, and NLog.Win32 to my startup project (Console Application)
- added static Logger just as in the tutorial (named logger)
- added LogManager.EnableLogging() to be sure
- added  logger.Info,  logger.Debug and logger.Error with strings to log

But neither does any output on the console show up, nor is any logfile created.
Then I created a "Applicationname.exe.nlog" file with just the .nlog-example of the tutorial, but still there is no output.

Have I completely missed something? Do you have any advice on how I could configure NLog properly?

Thanks,

Lars
Reply | Threaded
Open this post in threaded view
|

Re: Help me start logging with C# Express 2005

Jarek Kowalski
Administrator
Lars2b wrote
Hi,

I downloaded both the release and the last snapshot binaries, but didn't manage to get any log messages with C# Express edition 2005. What I did:
- added the references for NLog, NLog.DotNet, and NLog.Win32 to my startup project (Console Application)
- added static Logger just as in the tutorial (named logger)
- added LogManager.EnableLogging() to be sure
- added  logger.Info,  logger.Debug and logger.Error with strings to log

But neither does any output on the console show up, nor is any logfile created.
Then I created a "Applicationname.exe.nlog" file with just the .nlog-example of the tutorial, but still there is no output.

Have I completely missed something? Do you have any advice on how I could configure NLog properly?

Thanks,

Lars
1. You should defintely use one of the latest shapshots - 0.9 release has a known problem with .NET 2.0 support

2. Calling EnableLogging is not necessary

3. Try setting LogManager.ThrowExceptions = true; in your code to be notified should any problems occur.

4. Make sure that yourapp.exe.nlog is in the same directory as yourapp.exe - otherwise NLog will not read it

5. The easy way would be to add App.config to your application and create <nlog> config section. VS.NET will automatically copy app.config to yourapp.exe.config and ensure that it's in the right place.

If it doesn't help - please send your configuration file or even the entire project as a zip file to jaak -at- jkowalski -dot- net

Jarek
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Help me start logging with C# Express 2005

lars2b
Thanks Jarek,

I didn't realize that the "standard application config file" App.config can be added to the C# project in the Visual Studio IDE. After doing so and adding the standard configuration tags shown in the turorial, all went fine, thanks for your quick help. I still don't know why it did'nt work earlier, but well, does not matter anymore...

Lars

P.S. Perhaps you could add a sentence in the tutorial or the reference about adding an App.config file directly to the VS project, this might be helpful for other users as it's really the easiest way, I think.
Reply | Threaded
Open this post in threaded view
|

Re: Help me start logging with C# Express 2005

Nirav
In reply to this post by Jarek Kowalski
HI,


I had just started using nLog, downloaded the dlls and add ref to my project. I have a project am building in VS2010. I checked with forums and tutorials. I modified hte config adding nlog section below it is:

 <nlog  throwExceptions="true" internalLogFile="E:\nlog.txt"
        internalLogLevel="Error" autoReload="true"
        xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   
     
   
    <targets>
     
      <target name="file" xsi:type="File" fileName="${basedir}/log5.txt" />
    </targets>
    <rules>
      <logger name="*"  minlevel="Off" writeTo="file"/>     
    </rules>
  </nlog>


Then on startup page it self I added this (not sure if that was required).


  LogManager.ThrowExceptions = True
  LogManager.EnableLogging()

Further I added a popup where I have a button to click and there I assign string value to a integer variable, so I want that exception to send as email (for now I will test it to be written in a text file) but nothing seems to be happening, I changed the filename to "E:/log.txt", but still no luck.

I am also wondering if I need to code something if I want to write exceptions or send email or it will directly email the exception raised, sorry if I am behaving silly but I need to integrate this as soon as possible.


Thanks
Nirav