-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated InternalLogger to Create Directories If Needed #818
Updated InternalLogger to Create Directories If Needed #818
Conversation
Updated the InternalLogger to create directories if they are needed.
@@ -320,6 +320,7 @@ private static void Write(LogLevel level, string message, object[] args) | |||
var logFile = LogFile; | |||
if (!string.IsNullOrEmpty(logFile)) | |||
{ | |||
CreateDirectoriesIfNeeded(logFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move to constructor (performance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, that will make my unit test moot, but agree with the performance.
Thanks! Please check the first note. |
That's a lot of failed tests :/ |
That's a lot better. I forgot to remove out the unit test. Thoughts on moving all the static logic to an instance class that is initialized as a singleton. I think that will give you the performance and the unit testibility. |
I really liked the unit test. I forgot that calling the method in a static ctor is difficult to mock. But we can fix this :) New proposal:
/// <summary>
/// Gets or sets the file path of the internal log file.
/// </summary>
/// <remarks>A value of <see langword="null" /> value disables internal logging to a file.</remarks>
public static string LogFile { get; set; } This is even better then, because we also need the directories when changing the LogFile setting (and I see that the XML config is calling: Thanks in advance! |
Per the new proposal, moved the directory creation to the LogFile property setter. Added back the unit test and moved the asserts a bit.
I see the failing tests. Dunno why they fail. Maybe you can change |
The failed unit test was not my unit test. However, I do notice that the tests in there seem to randomly fail. It varies on my computer which one fails. My changes seems to have made the tests unstable. It might be threading since it's a static class. I'll dig in a bit more. |
yes, there are some tests which has race conditions. But that aren't those two failing tests. Do those tests successfully run on your local computer? |
My test seems to make the race conditions worse. As long as my test doesn't On Monday, July 27, 2015, Julian Verdurmen notifications@github.com wrote:
Sent from Gmail Mobile |
I think you should restore the original values of
it's not a race condition, but |
The CreateDirectoriesIfNeededTests causes unwanted side effect by causing the other tests (or this one) to randomly fail. To get around this, we set the InternalLogger.LogFile back to the previous log file, which resolves the issue.
Resetting the LogFile back to the previous value resolved the issue. It worked repeatedly on my machine, which it was not doing before. Thanks for the help. |
Are we good with this pull request? |
} | ||
catch (Exception exception) | ||
{ | ||
if (exception.MustBeRethrown()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need an log to the internallog here, because the internal log can also be to console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean something like this?
try
{
Directory.CreateDirectory(Path.GetDirectoryName(filename));
}
catch (Exception exception)
{
InternalLogger.Error("Cannot create needed directories {0}, Exception : {1}", Path.GetDirectoryName(filename), exception);
if (exception.MustBeRethrown())
{
throw;
}
}
Looks good! one small thing (because 'empty' catches are confusing) - see the code note. Can you fix that? |
Added logging to internal logging. Unfortunately, this will cause a lot of logs because the Write method calls LogFile, which is the source call.
8bd8c47
to
a5492ca
Compare
This is needed because this functionality does not exist for Silverlight.
Added a log if we are not rethrowing the exception. But I think this actually might cause issues unless we log only to the console. Whether we rethrow or not, the Write method uses the LogFile, which will probably not let that method finish. Thoughts? |
You're worried about infinite loops? I don't think this is a problem, but maybe we should unit test it to be sure. |
{ | ||
// Reset LogFile to the previous value | ||
InternalLogger.LogFile = previousLogFile; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert all the InternalLogger properties, to be sure. Maybe we should create a helper for that.
See #839
I did a small test myself and my fear was lacking any solid basis. I did a small update. Besides your last comment. I think it's good. Unsure what that last error is. Was there something new that was added? |
The compiler was generating a type that was a private nested type, which was missing the ThreadAgnosticAttribute. Because it was auto-generated there was not a way to add it.
Added an additional check for the failing test. It looked like there was inner type that was auto generated by the compiler for the ReplaceLayoutRendererWrapper. Running the test again with the additional check of t.IsPrivateNested showed that this was the only generated class. |
I will fix #839 soon and then we can use it in this PR. |
I recently enabled the Silverlight builds on appveyor. Probably this will cause the build errors |
I created a separate PR for your fix. (#844). Thanks for the fix! It should not lead to merge conflicts in this PR. |
Great. Let me know if you need anything after the other pull request is On Wednesday, August 12, 2015, Julian Verdurmen notifications@github.com
Sent from Gmail Mobile |
Yes I let you know. :) it's almost fixed :) |
#844 isn't working as expected. So we don;t have to change something in this PR for now. . |
Updated InternalLogger to Create Directories If Needed
Updated the InternalLogger to create directories if they are needed.
Resolves #802