Problem with Nlog configuration under Seven

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

Problem with Nlog configuration under Seven

gigi_81
Hi,

I'm trying to use Nlog in my visual c# desktop application.

Following the tutorial I have created the Nlog.config file using as fileName = "${basedir}/log.txt"

Running the application from visual studio all works fine and log file is created correctly. If I publish the application and install it on my pc (with windows seven), the log file is not created.

Can anyone help me to understand how I can solve this problem? (I think that this is a problem with UAC seven control, and I cannot use absolute path because the application will be installed on different machines)

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with Nlog configuration under Seven

Jason LaFlair
Administrator
The problem seems that you won't have permissions to that path for writing.

What I've done before for published apps is use the specialfolder layout renderer and write to where you're app would have permissions.

fileName="${specialfolder:folder=CommonApplicationData}/MyAppNameHere/log.txt"
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with Nlog configuration under Seven

gigi_81
Hi,

thanks for your suggestion, but in my case it doesn't work, because I'm using clickOnce distribution method.

I have solved using runtime configuration in this way:
 
NLog.Config.LoggingConfiguration config = new NLog.Config.LoggingConfiguration();
NLog.Targets.FileTarget target = new NLog.Targets.FileTarget();
config.AddTarget("file", target);

String dataDir = "${specialfolder:folder=LocalApplicationData}/YOURAPPNAME"; // useful only in development stage
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
     dataDir = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory;

target.FileName = dataDir + "/logs/${level}.txt";
NLog.Config.LoggingRule rule = new NLog.Config.LoggingRule("*",LogLevel.Debug,target);
config.LoggingRules.Add(rule);

LogManager.Configuration = config;
logger = LogManager.GetCurrentClassLogger();


Maybe, it may be useful for someone else.

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with Nlog configuration under Seven

Jason LaFlair
Administrator
That's odd as the parameter that I pasted was directly from a shared config used across several clickonce deployments we have.  I might have to dig deeper into this one.
Loading...