是否可以使用 log4net 写入文件夹中包含的事件日志?
目标是将我们的应用程序特定事件日志保存在以我们公司名称命名的文件夹中。因此,公司/应用程序1,公司/应用程序2。我更愿意通过配置或很少的代码来完成此任务。我尝试将 logName 设置为“MyFolder/MyLog”但无济于事。
这是我当前的 Appender 配置:
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="WARN" />
<levelMax value="FATAL" />
</filter>
<applicationName value="ExampleApp" />
<logName value="MyLog" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
The goal is to have our application specific event logs in a folder with the name of our company. So, Company/App1, Company/App2. I would prefer to accomplish this with configuration, or with very little code. I tried setting logName to "MyFolder/MyLog" to no avail.
Example of a folder in event viewer, reference the Microsoft folder
This is my current Appender configuration:
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="WARN" />
<levelMax value="FATAL" />
</filter>
<applicationName value="ExampleApp" />
<logName value="MyLog" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以直接在配置中设置路径,其中指定日志名称,只需指定完整路径即可。但是,您必须确保运行应用程序的任何用户都具有对该文件夹的写入权限。权限通常是此类问题的原因。
You can set the path directly in the configuration, where you specify the log name, just specify the full path. You must however make sure that whatever user your application is running under has write access to that folder. Permissions are usually the cause for problems like this.