Saustrup
Saustrup

Reputation: 788

NUnit fails with "Inaccessible logs: Security"

I'm relocating a build service from an ancient Windows XP server to Windows Server 2K12 R2, and now I'm stuck with what appears to be a permission issue:

During the "integration test" step of my build, NUnit fails:

Errors and Failures:
1) SetUp Error : Hidden.UAC.Service.IntegrationTest.TestSetUp
   SetUp : System.Security.SecurityException : The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
   at System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate)
   at Hidden.Cornerstone.Common.ApplicationManager.LogException(Exception e) in e:\Builder\TeamCity\buildAgent\work\9dbde7d05f17a8e5\Hidden.Cornerstone\Hidden.Cornerstone.Common\ApplicationManager.cs:line 99
   at Hidden.Cornerstone.Common.ApplicationManager.Initialize() in e:\Builder\TeamCity\buildAgent\work\9dbde7d05f17a8e5\Hidden.Cornerstone\Hidden.Cornerstone.Common\ApplicationManager.cs:line 91
   at Hidden.UAC.Service.IntegrationTest.TestSetUp.Init() in e:\Builder\TeamCity\buildAgent\work\9dbde7d05f17a8e5\Hidden.UAC\Hidden.UAC.Service.Impl.IntegrationTest\TestSetUp.cs:line 22

The build agent is running as the user BuildSrvService. I'm using TeamCity Professional 9.1.7 and NUnit 2.6.4 on a Windows Server 2012 R2 Datacenter server.

I'm assuming the solution here is to somehow grant the proper permissions on the event log to the user running the build agent, but I need a little help here :-)

Upvotes: 1

Views: 161

Answers (1)

Saustrup
Saustrup

Reputation: 788

Due to a couple of compatibility issues, we're - for now - holding on to an older version of NUnit which runs on .net 3.5. A security change introduced with Windows Server 2003 requires applications to be registered before being granted access to the event log.

See https://stackoverflow.com/a/7848414/1353645 and https://stackoverflow.com/a/4603820/1353645 for further information.

Quick fix: figure out your application name (look for EventLog.CreateEventSource in your source) and update your registry from an elevated PowerShell:

PS> $RegistryBase = "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Application"
PS> $ApplicationName = "MyApplicationName"

PS> New-Item `
        -Force `
        -Path $RegistryBase `
        -Name $ApplicationName

PS> New-ItemProperty `
        -Force `
        -Path "$RegistryBase\$ApplicationName" `
        -Name "EventMessageFile" `
        -PropertyType ExpandString `
        -Value "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll"

Upvotes: 1

Related Questions