I've written my first C#.NET WinForms application and am ready to publish the first build for users to install. I'm using log4net as my logging utility, and have it set as:
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\"/>
<param name="AppendToFile" value="true"/>
<param name="DatePattern" value="yyyy-MM-dd' Log.txt'" />
// etc
When I build my application, however, nothing ever gets logged. While running in visual studio, everything goes to /bin/Debug/Logs/yyyy-MM-dd Log.txt
.
How do I specify where my program should install to, and what the working directory should be?
Keep in mind this program is fairly minimal (<6K lines of code) and I don't really know the difference in all the publishing types inside of visual studio. I just want to distribute an .exe to my users and track errors under a directory such as C:\Program Files\myapp
. What am I doing wrong?
EDIT: When I right click the program and go to Properties from within the solution explorer, I'm setting the following options (which may be incorrect, I've never done this before):
- Build -> All Configurations -> Output Path:
C:\Program Files\myapp\bin\
- Debug -> All Configurations -> Working directory:
C:\Program Files\myapp\bin\
- Publish -> Publish Location:
C:\Program Files\myapp\Publish\
- Publish Wizard -> Publish Location:
C:\Program Files\myapp\Publish\
- Publish Wizard -> From a CD-ROM or DVD-ROM
- Publish Wizard -> The application will not check for updates
Are these settings correct or am I royally screwing something up? What I would like is for the user to be prompted an install location开发者_如何学Go (defaulted to: C:\Program Files\myapp), and this location always be used for the working directory (so I know where the log file is). How do I achieve this?
Since you are using Click Once for deployment, the application will not be in the typical C:\Program Files\myapp
directory.
Vista and Windows 7:
C:\Users\<UserName>\AppData\Local\Apps\2.0\<obscure foler>\<obscure folder>
Windows XP:
C:\Documents and Settings\<UserName>\LocalSettings\Apps\2.0\<obscure foler>\<obscure folder>
Dig around in those directories and you should see the log4net files.
Edit
An alternative to Click Once deployment is the Visual Studio installer: Walkthrough: Deploying a Windows-based Application. This will allow you to install the application in the standard C:\Program Files\myapp
directory.
I'd recommend you create few dummy projects with the installer to gain some familiarity with the various options. Initially, creating MSI's with the installer can seem daunting if you haven't used it before; after a bit of usage, the VS installer will become quite easy to use.
Another suggestion would be to test your installers on a virtual machine so you don't do anything inadvertently in your personal environment.
When running in Visual Studio the log files get written under the Debug
folder as that's where the exe is.
When you install the application to C:\Program Files\myapp
(or where ever) the logs will be created relative to that location and so should be in C:\Program Files\myapp\Logs/yyyy-MM-dd Log.txt
- assuming that the user has rights to create directories and files at that location.
The simplest way to prove this is to install the application and run it. Then check where the log file is created.
精彩评论