Get-DbaErrorLog without LogNumber parameter only reads first file
Before submitting a bug report:
- [X ] Ensure you are able to reproduce it on the latest released version (we release often)
- [X ] Verified this bug is not already reported in an issue
- [X ] Verified errors are not related to permissions
- [X ] Can reproduce in a clean PowerShell session (clean =
powershell -NoProfile)
Steps to Reproduce
# pick a data that spans into your second SQL Server event log file
Get-DbaErrorLog -SqlInstance $prodInstance -After '2018-12-04 20:30:00';
Expected Behavior
Reads from first and second file to get full list of logs that match -After
Actual Behavior
Only returns data from first file
I was able to get the data I needed today by adding the LogNumber parameter:
# enough files to get the dates noted in the -After
Get-DbaErrorLog -SqlInstance $prodInstance -After '2018-12-04 20:00:00' -LogNumber (0..6)
Environmental data
PowerShell 5.1
This would be a bit of a challange to handle because we have to pull every possible log on a given instance. Once you have the full dataset you then filter that out based on the date provided (before or after).
It would be doable, but very performance heavy potential is there....unless we can figure some PS magic to handle this and still support PS3+.
Right now though the command is not meant to be used without providing the log numbers...so changed this to a feature instead of a bug. We just missed adding logic to validate what parameter sets were provided.
@wsmelton I logged it as a bug due to the description of the function:
.DESCRIPTION
Gets the "SQL Error Log" of an instance. Returns all 10 error logs by default.
If the expected behavior isn't to return all 10, updating the description to reflect that it's just getting the first one fixes the bug in my mind. I don't need the functionality to deal with all 10 by default; I can sort that out on my own as necessary.
That detail was left out of your description.
I realized that once I read your comments; sorry.
As we only use $server.ReadErrorLog() (https://docs.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.management.smo.server.readerrorlog) if no LogNumber is supplied, this seems to be a bug within the SMO. As we are a bit behind with the SMOs, I think its useless to open an issue against the SMO. But I can add a workaround to loop through all the files. We could get the actual number with $server.NumberOfLogFiles if the number if configured, -1 if the default of 6 is used. But as $server.ReadErrorLog(99) returns instantly, we just brute force through all numbers - 99 is the maximum. With one loglile the order is from old to new, so we start with 99 and go down to 0. Will open a PR for that...