Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FileTarget - differentiate between fields that are absent vs intentionally disabled #6060

@0xNF

Description

@0xNF

NLog version: 6.0.6

Platform: .NET 10

Current NLog config (xml or C#, if relevant)

    <target xsi:type="File" name="incomingSyslogFiles"
      fileName="${gdc:item=logsDirectory}/lm/${event-properties:item=source}_${date:yyyyMMdd}.log"
      archiveEvery="Day"
      archiveSuffixFormat="_{0:0}"
      keepFileOpen="false"
      createDirs="true"
      layout="${message}" />

In this example, the ArchiveAboveSize, MaxArchiveDays, and MaxArchiveFiles are unset. The documentation specifies that "Zero or negative means disabled". This is what one sees when loading the FileTargets programmatically.

However, I'm doing some runtime level configuration work involving potentially overriding fields, and would like to be able to differentiate between fields that weren't set all versus what was intentionally unset. If I write -1 in the XML config file, my signal as the programmer involved is that "this field is deliberately not used, don't change it.", but when looking at FileTargets in code it's not possible to tell the difference between that and a field that was just omitted from the XML file.

In an ideal world these fields would become nullable int? to indicate their not-yet-set status but I think that might be a breaking change.

My hack solution right now is to define my own negative value constant (-2 in this case) to denote intentionally disabled, but it requires keeping other devs up to date on that custom extension, so I'd like to have something more universal if possible.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions