locked
c#, Nlog and change target RRS feed

  • Question

  • i am running windows service, and i want when i run in debugto to write to console and when as service to event viewer. 1. in powershell i set

    New-EventLog –LogName Application –Source "mySource"

    i do init when service start :

    public static void InitLogger()
    {
        NLog.Targets.Target target = null;
    
        target = LogManager.Configuration.FindTargetByName("eventlog");
    
        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Info);
        LogManager.Configuration.Reload();
    
    }

    to test this i change it in both cases to write to "eventlog" even in debug mode. but nothing is writing to event viewer (VS is running in admin mode) i set in each class

    private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

    is there should be another configuration?


    update : for some reason event written to

    Even Viewer

    • Edited by want 2 Learn Thursday, March 14, 2019 11:41 AM added image
    • Moved by Dave PatrickMVP Thursday, March 14, 2019 12:42 PM looking for forum
    Thursday, March 14, 2019 11:20 AM

Answers