Имам проблем с nlog, докато изпълнявам конзолното си приложение като скрит процес. Записите в дневника не са записани.
Имам 2 конфигурирани цели (конзола, файл) в моя файл nlog.config, които работят перфектно, ако ръчно стартирам конзолното си приложение.
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"
globalThreshold="Debug"
internalLogFile="c:\nlog.txt" internalLogLevel="Trace">
<variable name="defaultLayout" value="${longdate} | ${level} | ${logger} | ${message}"/>
<variable name="logFilename" value="logs/${shortdate}.Scheduler.log"/>
<variable name="errorLogFilename" value="logs/${shortdate}.Scheduler.log"/>
<targets async="false">
<target xsi:type="Console" name="console" layout="${defaultLayout}"/>
<target name="file" xsi:type="File" fileName="${logFilename}" layout="${defaultLayout}" />
<target name="errorFile" xsi:type="File" fileName="${errorLogFilename}" layout="${defaultLayout}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file,console" />
<logger name="*" minlevel="Warn" writeTo="errorFile" />
</rules>
</nlog>
моят код, отговорен за стартиране на процеса на конзолното приложение:
let setupProcess (enviromentName) (parameter) =
let targetPath = getTargetPath enviromentName
let executable = System.IO.Path.Combine(targetPath, executable)
let startInfo = new ProcessStartInfo()
startInfo.WindowStyle <- System.Diagnostics.ProcessWindowStyle.Normal
startInfo.FileName <- executable
startInfo.Arguments <- parameter
startInfo.RedirectStandardOutput <- true
startInfo.UseShellExecute <- false
startInfo
и за стартиране на процеса:
[<Fact>]
let ``Run in debug mode``() =
createEnviroment "debugEnv"
let setup = setupProcess "debugEnv" "debug"
use process' = Process.Start(setup)
process'.BeginOutputReadLine() |> ignore
process'.OutputDataReceived.Add(fun(args) -> printf "%s\n" args.Data)
process'.WaitForExit(10000) |> ignore
process'.Kill()|> ignore
моят проект може да бъде намерен тук: https://github.com/aph5nt/cronix
Console.WriteLine
, без участието на NLog? - person Fyodor Soikin   schedule 23.03.2015