Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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.
// 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment