为什么 Log4Net 不在生产中创建日志文件?

发布于 2024-08-02 04:10:37 字数 612 浏览 4 评论 0原文

我使用的是VS2005、网站项目、Web部署项目和Log4Net。 当我在本地开发时,我可以使用日志记录。 我可以看到日志文件,一切都很好。 当我构建网站时(使用 Web 部署项目),我使用部署作为单个 DLL 选项。 然后,当我检查日志文件所在的位置时,我看不到任何文件。

有没有办法解决这个问题。 我认为将调试值添加到应用程序设置不会有帮助,因为我没有控制台,因为它是一个网站。

编辑 我不想最后一次浪费 150 次。 我将开发环境的内部跟踪与生产环境的跟踪进行了比较。 我的开发环境跟踪显示了 Xml 配置器的调用,而生产环境则没有。 我在 application_start() 方法的 global.asax 中有代码。 我将调试代码放在那里,它在开发中被调用,但在生产中却没有被调用。

我认为这就是网络部署项目引起一些问题的地方。 global.asax 是否被编译到单个 DLL 中? 当我在部署目录中进行构建时,我会看到一个 global.compiled 文件。 这必须进入生产中的 bin 文件夹吗? 或者 global.asax 代码是在单个 DLL 中吗? 将两者都放在 bin 文件夹中或仅将 DLL 放在其中不会改变任何内容。

I am using VS2005, a website project, a web deployment project and Log4Net. I can use logging when I am developing locally. I can see the log files and everything is fine. When I build my website, (using the web deployment project), I use the deploy as a single DLL option. When I then check the locations of where my log files should be I cannot see any files.

Is there a way to troubleshoot this. I don't think adding the debug value to the App Settings will help because I don't have a console because it is a website.

EDIT
I don't want the 150 rep to go to waste so one last time. I compared the internal trace from my dev environment to the trace from the production. My dev environment trace shows the call the Xml Configurator where the production one does not. I have code in the global.asax on application_start() method. I put debug code in there and it is getting called in dev but not in production.

I think this is where the web deployment project is causing some issues. Does the global.asax get compiled into the single DLL? When I do a build in the deployment directory I see a global.compiled file. Must this go into the bin folder in production? Or is the global.asax code in the single DLL? Having both in the bin folder or the just the DLL didn't change anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

楠木可依 2024-08-09 04:10:37

工作进程是否有足够的权限写入日志目录? 我猜情况并非如此。 您可能想要授予工作进程组写入目录的权限,看看是否可以解决您的问题。

Does the worker process have sufficient privileges to write to the log directory? I'm guessing that's not the case. You might want to give the worker process group rights to write to the directory and see if that fixes your problem.

瑾夏年华 2024-08-09 04:10:37

将其添加到 AssemblyInfo.cs 文件中并检查

[assembly: log4net.Config.XmlConfigurator(Watch=true)]

Add this in AssemblyInfo.cs file and check

[assembly: log4net.Config.XmlConfigurator(Watch=true)]
左耳近心 2024-08-09 04:10:37

我已经找到问题了。 权限是正确的。 事实证明,使用 Web 部署项目还会在根目录中创建一个 precomplid.config 文件。 我没有将其复制到生产环境中。 一旦进入,一切就都开始工作了。 抱歉没有人拿到赏金。

I have found the problem. Permissions were CORRECT. Turns out that using a web deployment project also creates a precompliled.config file in the root. I had not copied that to the production enivornment. As soon as that was in the everything worked. Sorry no one got the bounty.

鹤舞 2024-08-09 04:10:37

看起来问题的根源是 global.asax 中的 Application_Start 事件没有触发。

从 VS 2005 部署到 Windows 2003 时存在一个“已知”问题,即 Application_Start 不会触发。

Global.asax.cs 的内容将被编译到 dll 中。 但是,除非文件 Global.asax 存在,否则 Application_Start 将不会运行。

以下是一些相关链接:

http://accidentaltechnologies.com/asp-net/application_start-not-firing-and-the-globalasax/

http://www.velocityreviews.com/forums/t300292-web-deployment -projects-globalasax-problem.html

上述链接中还介绍了一些其他可能性。

希望这对

设拉子有帮助

It looks like the root of your problem is that the Application_Start event in global.asax is not firing.

There is a "known" problem when deploying from VS 2005 to Windows 2003, that the Application_Start does not fire.

The contents of Global.asax.cs will be compiled into the dll. But the Application_Start will not run unless the file Global.asax is present.

Here are a couple of relevant links:

http://accidentaltechnologist.com/asp-net/application_start-not-firing-and-the-globalasax/

http://www.velocityreviews.com/forums/t300292-web-deployment-projects-globalasax-problem.html

There are some other possibilities that are covered in the above links.

Hope this helps

Shiraz

习ぎ惯性依靠 2024-08-09 04:10:37

我以前也遇到过这种情况,并且是 ASPNET 用户在需要时创建文件的权限。可以检查Windows事件日志中是否有任何内容表明这一点?

为了检查这种情况(我们观察观察者!),我们通过使用 OutputDebugString() 通过 pinvoke。。我们还将其放入 try catch 中,以确保我们发现与此相关的错误,因为使用它来正确记录非常重要。

This has happened to me before and was permissions on the ASPNET user to create the files where needed. Can check if there is anything in the windows event log indicating this?

To check for the kind of thing (we watch the watcher!) we output where the log4net was going to work by writing this out using the OutputDebugString() via pinvoke.. We also put this in a try catch to ensure that we discover errors regarding this as it's very important to use to be able to log correctly.

绿萝 2024-08-09 04:10:37

固定的。 在“属性 -> ”中添加具有“写入”权限的用户(启动 IIS 工作进程) 安全-> 编辑应在其中创建“日志”文件的项目文件夹。

Fixed. Add the user (which was start the IIS work process) with 'write' rights in 'Properties -> Security -> Edit' for project folder where should be created "Log" file.

痞味浪人 2024-08-09 04:10:37

检查预期输出目录的权限并确保 Web 服务可以写入该目录。 最简单的方法是运行 filemon.exe(SysInternals 应用程序)并相应地限制它。 这应该会告诉您是否出现任何故障,并且您可以根据需要进行修复

Check the permissions on the expected output directory and ensure that the web-service can write to it. The simplest way to do it is to run filemon.exe (a SysInternals app) and restrict it accordingly. This should tell you if anything fails and you can fix as necessary

失而复得 2024-08-09 04:10:37

确保 log4net get 配置正确。也许 dll 没问题,但配置文件丢失了? log4net 可能在那里,但只是没有任何活动的附加程序。

Make sure log4net get's configured properly. Maybe the dll is alright but the config file is missing? log4net could be there but just does not have any active appenders.

谜兔 2024-08-09 04:10:37

为了确保 log4net 是否配置正确,我创建了一个记录到端口 9090 的 UDP Appender。我使用链锯 http://logging.apache.org/chainsaw/index.html 检查日志条目。

有了这个,您可以检查至少一些日志条目已完成并且记录器正在运行。

UDP Appender 配置

<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
        <remoteAddress value="localhost" />
        <remotePort value="9090" />
        <layout type="log4net.Layout.XmlLayoutSchemaLog4j">
            <locationInfo value="true" />
        </layout>
</appender>

Chainsaw XML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> 
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">    
    <plugin name="LocalReceiver" class="org.apache.log4j.net.UDPReceiver">
        <param name="Port" value="9090" />
    </plugin>    
</log4j:configuration>

to make sure if log4net is configured properly i do create a UDP Appender that logs to port 9090. i use chainsaw http://logging.apache.org/chainsaw/index.html to check the log entries.

with this you you can check that at least some logs entries are done and that the logger is running.

UDP Appender Config

<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
        <remoteAddress value="localhost" />
        <remotePort value="9090" />
        <layout type="log4net.Layout.XmlLayoutSchemaLog4j">
            <locationInfo value="true" />
        </layout>
</appender>

Chainsaw XML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> 
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">    
    <plugin name="LocalReceiver" class="org.apache.log4j.net.UDPReceiver">
        <param name="Port" value="9090" />
    </plugin>    
</log4j:configuration>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文