使用 log4net 在 .NET 上发布 C# 应用程序?
我已经编写了第一个 C#.NET WinForms 应用程序,并准备发布第一个版本以供用户安装。我使用 log4net 作为我的日志记录实用程序,并将其设置为:
<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
但是,当我构建我的应用程序时,不会记录任何内容。在 Visual Studio 中运行时,所有内容都会转到 /bin/Debug/Logs/yyyy-MM-dd Log.txt
。
如何指定程序应安装到的位置以及工作目录应该是什么?
请记住,这个程序相当小(<6K 行代码),而且我真的不知道 Visual Studio 内所有发布类型的差异。我只想将 .exe 分发给我的用户并跟踪 C:\Program Files\myapp
等目录下的错误。我做错了什么?
编辑:当我右键单击该程序并从解决方案资源管理器中转到“属性”时,我设置以下选项(这可能不正确,我以前从未这样做过):
- 构建 -> ;所有配置 ->输出路径:
C:\Program Files\myapp\bin\
- 调试 ->所有配置 ->工作目录:
C:\Program Files\myapp\bin\
- 发布 ->发布位置:
C:\Program Files\myapp\Publish\
- 发布向导 ->发布位置:
C:\Program Files\myapp\Publish\
- 发布向导 ->从 CD-ROM 或 DVD-ROM
- 发布向导 ->该应用程序不会检查更新
这些设置正确还是我搞砸了?我想要的是提示用户安装位置(默认为:C:\Program Files\myapp),并且该位置始终用于工作目录(所以我知道日志文件在哪里)。我该如何实现这一目标?
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 (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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您使用 Click Once 进行部署,因此应用程序不会位于典型的
C:\Program Files\myapp
目录中。Vista 和 Windows 7:
Windows XP:
在这些目录中进行挖掘,您应该会看到 log4net 文件。
编辑
单击一次部署的替代方法是 Visual Studio 安装程序:演练:部署基于 Windows 的应用程序。这将允许您将应用程序安装在标准
C:\Program Files\myapp
目录中。我建议您使用安装程序创建一些虚拟项目,以熟悉各种选项。最初,如果您以前没有使用过安装程序,那么使用安装程序创建 MSI 可能会让人望而生畏。经过一段时间的使用,VS安装程序会变得非常容易使用。
另一个建议是在虚拟机上测试安装程序,这样您就不会在个人环境中无意中执行任何操作。
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:
Windows XP:
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.
在 Visual Studio 中运行时,日志文件将写入
Debug
文件夹下,因为该文件夹就是 exe 所在的位置。当您将应用程序安装到
C:\Program Files\myapp
(或任何位置)时,日志将相对于该位置创建,因此应该位于C:\Program Files\myapp\ Logs/yyyy-MM-dd Log.txt
- 假设用户有权在该位置创建目录和文件。证明这一点的最简单方法是安装应用程序并运行它。然后检查日志文件的创建位置。
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 inC:\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.