Skip to content

Target does not update on LogManager.ReconfigExistingLoggers(); #39

Open
@bobcat1506

Description

@bobcat1506

We store our connection strings and credentials outside of our app in a secrets vault, but we like to keep the rest of our config in config files. We marry the two just before starting up the app. The following code works great with other targets such as the DatabaseTarget, but doesn't work with MongoTarget.

    static void Main(string[] args)
    {
        Logger logger = NLog.LogManager.GetCurrentClassLogger();

        // do startup activities like building the host and log to files
        try
        {
            // build host
        }
        catch (Exception ex)
        {
            // logger.LogException()
            // the logger never writes anything to mongo and never throws an error
        }

        // set connection string after retrieving username/password from secrets store
        var mongo = LogManager.Configuration.FindTargetByName("mongoCustom") as MongoTarget;
        mongo.ConnectionString = "mongodb://localhost/Logging";
        LogManager.ReconfigExistingLoggers();

        // run the host
        try
        {
            // host.Run()
        }
        catch (Exception ex)
        {
            // logger.LogException()
        }
    }

<target xsi:type="Mongo" name="mongoCustom" includeDefaults="false" collectionName="CustomLog" cappedCollectionSize="26214400">

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions