I'm trying to store my logs to a drive in the network. I wrote an nlog extension module:
module NLogExtension
open System.Text
open NLog
open NLog.LayoutRenderers
open NLog.Config
open System.IO
[<LayoutRenderer("FindAvailableDrive")>]
type FindAvailableDriveLayoutRenderer() =
inherit LayoutRenderer()
let mutable validDrive = ""
[<DefaultParameter>]
member val DriveCandidates = "" with get, set
member private x.findValidDrive(): string =
if x.DriveCandidates = null || x.DriveCandidates = ""
then
if Directory.Exists("V:")
then validDrive <- "V:"
else validDrive <- "S:"
else validDrive <- "S:"
validDrive
override x.Append(builder: StringBuilder, logEvent: LogEventInfo) = builder.Append(x.findValidDrive(): string) |> ignore
This is going to either store in V: or S: if V doesn't exist.
This is the nlog section in the App.config file:
<nlog
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="Solk.NLogExtension" />
</extensions>
<targets>
<target name="logfile" xsi:type="File" fileName="logfile.txt" />
<target name="indexCheckLog"
xsi:type="File"
fileName="${FindAvailableDrive}/logs/indexChecklog.txt"
layout="${callsite} - ${message}"
archiveFileName="${FindAvailableDrive}/logs/archives/log.info.${shortdate}.txt"
archiveEvery="Day"
archiveNumbering = "Rolling"
maxArchiveFiles="7"
concurrentWrites="false"
/>
<target name="console" xsi:type="Console" />
</targets>
<rules>
<logger name="indexCheckLogger" minlevel="Trace" writeTo="indexCheckLog" final="true"/>
<logger name="*" minlevel="Trace" writeTo="logfile" />
<logger name="*" minlevel="Info" writeTo="console" />
</rules>
</nlog>
The target I'm concerned with is indexCheckLog. As you can see both the current log and the archive are using the extension ${FindAvailableDrive}
. You can see I added the extensions tag on top of the file with assembly Solk.NLogExtension
(Solk is the assembly title and project name and NLogExtension is the name of the module as can be seen in the first line of the extension module).
However, not a single log is in these folders. Not in V or S. Not sure what I'm doing wrong and no exceptions are being thrown or any indications of what is exactly going on.