Pop
Pop

Reputation: 525

log4net not logging after Impersonate

Why my log4net not logging after Impersonate, start logging after Undo?

testDebug 6 is not log.

What can I do about it?

        logger.Debug("testDebug 5");
        // The token that is passed to the following constructor must 
        // be a primary token in order to use it for impersonation.
        WindowsIdentity newId = new WindowsIdentity(dupeTokenHandle);
        WindowsImpersonationContext impersonatedUser = newId.Impersonate();
        logger.Debug("testDebug 6");
        // Check the identity.
        // Console.WriteLine("After impersonation: "
        //    + WindowsIdentity.GetCurrent().Name);
        if (Config.DebugMode().Trim().ToUpper() == "ON")
            logger.Debug("After impersonation: " + WindowsIdentity.GetCurrent().Name);

        //////// Put your code here ////////

        ReceiveEmail();

        ///////////////////////////////////

        // Stop impersonating the user.
        impersonatedUser.Undo();
        logger.Debug("testDebug 7");

Upvotes: 0

Views: 376

Answers (1)

Richard Schneider
Richard Schneider

Reputation: 35477

Most likely the impersonated user does not have write/append access to the log file.

Upvotes: 2

Related Questions