I want to create an new event log Event Source to log my webAPI app to when I Import Application through IIS.
I publish my application to a web deploy folder (zip) file in VS2015 and import from this.
I have found this code to create the event source:
if ([System.Diagnostics.EventLog]::SourceExists("myWeb.API") -eq $false) {
[System.Diagnostics.EventLog]::CreateEventSource("myWeb.API", "Application")
}
and I can put this in a EventSource.ps1 file which does what I want when I run it from a prompt.
How can I execute this during the IIS Import Application process?
I have tried using the .pubxml file but which element to use/override/call-it-via baffles me - I've tried AfterAddIisSettingAndFileContentsToSourceManifest and PipelineDependsOn.
<Target Name="CustomCreateEventSource">
<Message Text="Create Event Source" Importance="high"/>
<PropertyGroup>
<EventSource Condition=" '$(EventSource)'=='' ">
myWeb.API
</EventSource>
</PropertyGroup>
<Exec Command="powershell.exe"
-NonInteractive
-executionpolicy Unrestricted
-file "$(PublishUrl)Publish\EventSource.ps1" "$(EventSource)"" /></Target>
I'd rather it was done via IIS Import Application, as a 1-hit process, and not a:
- Import Application
- Run the powershell
because it'll be imported by not-necessarily technical users.
Many thanks for taking the time to assist!