如何将日志文件位置传递给 IErrorHandler?
我有一个托管 WCF 服务的 C# Windows 服务(两个独立的项目)。我的 WCF 服务项目实现了 IErrorHandler
,我想用它来将错误记录到文件中。我的 Windows 服务正在对文件进行一些日志记录,我希望我的 IErrorHandler
写入同一个文件。
我怎样才能做到这一点(无需在 IErrorHandler
中对文件名进行硬编码)?
I've got a C# Windows Service hosting a WCF Service (two separate projects). My WCF Service project implements IErrorHandler
, which I'd like to use to log errors to a file. My Windows Service is doing some logging to a file, and I'd like my IErrorHandler
to write to that same file.
How can I accomplish this (without hardcoding the filename in IErrorHandler
)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用公共静态文件路径属性创建一个新的静态类
在该类中,从 Windows 服务 app.config 加载日志文件的文件路径。
然后还从 WCF 服务引用该类,并且您应该能够使用存储在公共静态文件路径属性中的相同值。
Create a new static class with a public static filepath property
In that class, load the filepath to the log file from the windows service app.config.
Then also reference that class from your WCF service and you should be able to use the same value stored in the public static filepath property.