Created
January 25, 2017 18:17
-
-
Save deadlydog/f330beebb60398c64015b8ab4f7b98c2 to your computer and use it in GitHub Desktop.
Updates Log4Net appenders to adjust where they are set to write their log files to, to instead write them to the ClickOnce application's data directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If we are running via ClickOnce, we need to adjust the path where the log files are written to, otherwise they won't be written at all. | |
if (ApplicationDeployment.IsNetworkDeployed) | |
{ | |
var dataDirectory = ApplicationDeployment.CurrentDeployment.DataDirectory; | |
foreach (var appender in LogManager.GetRepository().GetAppenders()) | |
{ | |
var fileAppender = appender as FileAppender; | |
if (fileAppender != null) | |
{ | |
var pathToReplace = Directory.GetParent(Directory.GetParent(fileAppender.File).FullName).FullName; | |
fileAppender.File = fileAppender.File.Replace(pathToReplace, dataDirectory); | |
fileAppender.ActivateOptions(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment