locked
NLog change eventlog target to something else than Application RRS feed

  • Question

  •  Changed the target log from Application to "xxxx". I removed the Source using powersheel and the created it under "xxxx". when i write event's it doesn't appear anywhere

    target = LogManager.Configuration.FindTargetByName("eventlog");
    mode = config.RUN_MODE;
    LogManager.Configuration.RemoveTarget("console");
    ((NLog.Targets.EventLogTarget)target).Log = "xxxx";
    LoggingConfiguration loggingConfiguration = new LoggingConfiguration();
    var asyncFileTarget = new AsyncTargetWrapper(target);
    loggingConfiguration.AddTarget("eventlog", asyncFileTarget);
    
    LogManager.Configuration.AddRule(LogLevel.Info, LogLevel.Fatal, target, mode, true);
    LogManager.Configuration = loggingConfiguration;
    LogManager.ReconfigExistingLoggers();



    I removed and added using powershell the new log and source (the "xxxx" log was created):


    Remove-EventLog -Source "mySource" 
    New-EventLog -LogName xxxx -Source "mySource code here

    i tried all, i even change the log="xxxx" in the app.config but it still doesn't write to the new event log

    any idea?



    • Edited by want 2 Learn Thursday, May 23, 2019 7:42 PM source code
    • Moved by CoolDadTx Tuesday, May 28, 2019 1:57 PM Third party product
    Thursday, May 23, 2019 7:41 PM

All replies

  • Hi want 2 Learn,

    Thank you for posting here.

    For your question , please refer to the thread below.

    https://stackoverflow.com/a/2191967

    In this link, the path of log output is specified.

    Hope this helps.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 24, 2019 7:26 AM
  • the example is about writing to log files

    my case I writing to event viewer

    Friday, May 24, 2019 8:19 AM
  • Hi want 2 Learn,

    In the thread below there is a way to write to the event log, you can try it:

    https://stackoverflow.com/questions/25725151/write-to-windows-application-event-log

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 28, 2019 7:41 AM
  • to Application log I write twithought any problem,

    when I want to write to another log file it doesn't work

    Tuesday, May 28, 2019 7:12 PM