diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b7d4ef6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/Installer.cs b/Installer.cs index d01278c..615d8a2 100644 --- a/Installer.cs +++ b/Installer.cs @@ -25,6 +25,14 @@ public class Installer : System.Configuration.Install.Installer public override void Install(IDictionary stateSaver) { +#if DEBUG + if (!Debugger.IsAttached) + { + Debugger.Launch(); + } + Debugger.Break(); +#endif + base.Install(stateSaver); previousEnableEventLog = InstallerConfig.EnableEventLog; @@ -70,6 +78,14 @@ public override void Rollback(IDictionary savedState) public override void Uninstall(IDictionary savedState) { +#if DEBUG + if (!Debugger.IsAttached) + { + Debugger.Launch(); + } + Debugger.Break(); +#endif + base.Uninstall(savedState); try @@ -112,50 +128,41 @@ private void InstallTask(IDictionary stateSaver) // init. task scheduler service engine using (TS.TaskService ts = new TS.TaskService()) { - // check if scheduler engine is V2 (starting with + // check if scheduler engine is V2 isNewGen = (ts.HighestSupportedVersion >= new Version(1, 2)); TS.TaskDefinition td = ts.NewTask(); + td.RegistrationInfo.Description = DefaultTaskDescription; - try - { - td.RegistrationInfo.Description = DefaultTaskDescription; - - td.Actions.Add( - new TS.ExecAction(targetExeFileInfo.FullName) - ); - - // triggers every day, one hour after midnight UTC - TS.DailyTrigger trigger = new TS.DailyTrigger(); - trigger.StartBoundary = new DateTime(1982, 4, 15, 1, 0, 0, DateTimeKind.Utc); - td.Triggers.Add(trigger); - - if (isNewGen) - { - td.Settings.Priority = ProcessPriorityClass.BelowNormal; - } - - td.Settings.ExecutionTimeLimit = TimeSpan.FromDays(1d); - td.Settings.DisallowStartIfOnBatteries = false; - td.Settings.StopIfGoingOnBatteries = false; - - // the task needs to be explicitly enabled by user - td.Settings.Enabled = false; - - TS.Task task = ts.RootFolder.RegisterTaskDefinition( - DefaultTaskName, - td, - TS.TaskCreation.CreateOrUpdate, - isNewGen ? "S-1-5-18" : null, - LogonType: TS.TaskLogonType.ServiceAccount - ); - taskName = task.Name; - } - finally + td.Actions.Add( + new TS.ExecAction(targetExeFileInfo.FullName) + ); + + // triggers every day, one hour after midnight UTC + TS.DailyTrigger trigger = new TS.DailyTrigger(); + trigger.StartBoundary = new DateTime(1982, 4, 15, 1, 0, 0, DateTimeKind.Utc); + td.Triggers.Add(trigger); + + if (isNewGen) { - // TS.TaskDefinition have .Dispose() method but isn't IDisposable o_O - td.Dispose(); + td.Settings.Priority = ProcessPriorityClass.BelowNormal; } + + td.Settings.ExecutionTimeLimit = TimeSpan.FromDays(1d); + td.Settings.DisallowStartIfOnBatteries = false; + td.Settings.StopIfGoingOnBatteries = false; + + // the task needs to be explicitly enabled by user + td.Settings.Enabled = false; + + TS.Task task = ts.RootFolder.RegisterTaskDefinition( + DefaultTaskName, + td, + TS.TaskCreation.CreateOrUpdate, + isNewGen ? "SYSTEM" : null, + LogonType: TS.TaskLogonType.ServiceAccount + ); + taskName = task.Name; } // remembers the registered task name for future uninstall @@ -166,7 +173,7 @@ private void InstallTask(IDictionary stateSaver) this.Context.LogMessage("Information: The scheduled task is DISABLED by default !"); // TODO don't advise to use schtasks.exe for older windows (which older ones ?) - this.Context.LogMessage("Information: Execute this command line to enable: schtasks.exe /Change /TN \"" + taskName + "\" /ENABLE"); + this.Context.LogMessage("Information: Execute this command line to enable: SCHTASKS /Change /TN \"" + taskName + "\" /ENABLE"); } private void UninstallTask(IDictionary savedState) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 26b9cd0..33fe22c 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -24,6 +24,6 @@ [assembly: AssemblyConfiguration("Release")] #endif -[assembly: AssemblyVersion("1.8.1.0")] -[assembly: AssemblyFileVersion("1.8.1.0")] -[assembly: AssemblyInformationalVersion("1.8.1")] \ No newline at end of file +[assembly: AssemblyVersion("1.8.2.0")] +[assembly: AssemblyFileVersion("1.8.2.0")] +[assembly: AssemblyInformationalVersion("1.8.2")] \ No newline at end of file diff --git a/README.md b/README.md index 083834c..dbcbc2e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # IIS Log Rotator Microsoft Internet Information Services Log Rotation program. ---- - ## Features 1. Autodetects installed IIS services and file logging settings @@ -38,8 +36,6 @@ Web Management Service (WMSvc) logs are __not yet__ supported. * Windows Server 2008 / Vista only: IIS 6 Metabase Compatibility feature * Administrator rights (because of WMI and IIS Metabase readings) ---- - ## How to run 1. Extract the program to a local folder @@ -52,15 +48,14 @@ If you need to execute the program daily and have reports to Windows Event Log, you should register it to Windows Task Scheduler. 1. Execute `install.cmd` with Administrator rights -2. Modify scheduled task named `IIS Logs Rotation` if not satisfied with default settings (every day at 1:00 am UTC) +2. Modify scheduled task named `IIS Logs Rotation` manually if not satisfied with default settings (every day at 1:00 am UTC) +3. Enable scheduled task named `IIS Logs Rotation` manually, or execute `SCHTASKS /Change /TN "IIS Logs Rotation" /ENABLE` ## How to uninstall / unschedule * To remove everything, execute `uninstall.cmd` with Administrator rights * To disable the scheduled task, disable Windows scheduled task named `IIS Logs Rotation`, or execute `SCHTASKS /Change /TN "IIS Logs Rotation" /DISABLE` ---- - ## Settings Open the `IisLogRotator.config` file with an XML-aware editor (like [Visual Studio Code](http://code.visualstudio.com), [Sublime Text](http://www.sublimetext.com)) to avoid errors. @@ -93,7 +88,16 @@ Example for `W3SVC1` Website settings, to do deletion only after 30 days : ``` -### `defaultSettings` / `siteSettings` allowed values +### `rotation` element allowed attribute values + +| Attribute | Values | +| --- | --- | +| `enableEventLog` | `true` to enable Windows event log reports or `false` (default) to disable | + +Windows event logs reports are enabled when the program is installed using `install.cmd` and should not be enabled without, +or Windows will complain about missing event log source identifier. + +### `defaultSettings` / `siteSettings` elements allowed attribute values | Attribute | Values | | --- | --- |