Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog doesn't logging with ClickOnce

I am implementing logging in my app via NLog. This is my Nlog.Config:

 <?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <targets async="true">
    <target xsi:type="File"
            name="ExceptionTarget"
            fileName="LOG.txt"
            layout="${date:format=dd MMM yyyy HH-mm-ss} ${uppercase:${level}} ${newline}${message} ${exception::maxInnerExceptionLevel=5:format=ToString}${newline}${stacktrace}${newline}"/>
  </targets>

  <targets async="true">
    <target xsi:type="File"
            name="InfoTarget"
            fileName="LOG.txt"
            layout="${date:format=mm-ss} ${uppercase:${level}} ${newline}${message} ${newline}"/>
  </targets>

  <rules>
    <logger name="*" level="Error" writeTo="ExceptionTarget"/>
    <logger name="*" level="Info" writeTo="InfoTarget"/>
  </rules>
</nlog>

When I deploy the app out with ClickOnce, no log.txt file is being created. No errors occur, and my app runs as normal, but nothing is happening.

How to solve this problem?

like image 816
Corequatro Avatar asked Dec 20 '12 16:12

Corequatro


People also ask

How do I start logging with NLog?

Create a Console Application project in Visual Studio. Install NLog and its dependencies. Create and configure the NLog logger. Integrate the logger into the C# Console Application.

Is NLog asynchronous?

NLog 1.0 supports asynchronous logging, but there is no good support for asynchronous exception handling. This is because wrappers targets are not capable of receiving exceptions which are raised on other threads.

How does NLog work in C#?

NLog is “a free logging platform for . NET, Silverlight and Windows Phone with rich log routing and management capabilities. It makes it easy to produce and manage high-quality logs for your application regardless of its size or complexity.”

Where are NLog logs stored?

nlog file can be found at: C:\Program Files (x86)\Pleasant Solutions\Pleasant Password Server\www\web. nlog.


1 Answers

The ClickOnce installer is not deploying the NLog.config file when the software is installed, so your app do not have any logging configuration.

Solution:

  1. You could merge the logging config into your app.config file.
  2. Nlog.config must have: Build Action: Content and Copy to Output Directory: Copy always.
like image 154
Serhii Kyslyi Avatar answered Oct 17 '22 01:10

Serhii Kyslyi