log4net ....单独的日志文件
每次在 WCF 服务中执行特定过程时,我都会写出一个单独的日志。我已经使用 log4net 为整个应用程序提供了标准日志。我是否应该为特定进程添加附加程序和过滤器,然后将其删除?此过程涉及处理已上传的文件。还有其他想法吗???
I am going to write out a separate log for each time I do a certain process in my WCF service. I have a standard log for the entire application already using log4net. Should I just add an appender and filter for the particular process, then remove it? This process deals with processing a file that was uploaded. Any other ideas???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我以前做过类似的事情,我们使用了这样的代码:
Ollie
I'ved do something similiar before, we used code something like this:
Ollie
好吧,您创建一个 ILog 接口的自定义实现,它也实现 IDisposable 怎么样?您在创建时添加附加程序,并在释放它时将其删除......
例如。
Okay how about the you create a custom implementation of the ILog interface that also implements IDisposable - you add the appender when it's created and remove it when it's disposed...
eg.
您可以很容易地做到这一点,但这意味着将您自己绑定到特定的实现而不是接口。例如:
由于附加程序仅在
ProcessUpload
运行时出现,因此这应该会给您带来所需的效果。uploadLogAppender
只是一个FileAppender
实例,其文件名由您确定,例如按每次上传确定。You can do this quite easily, but it means tying yourself to a specific implementation rather than the interfaces. For example:
As the appender is present only while
ProcessUpload
runs, this should give you the effect you need.uploadLogAppender
is just aFileAppender
instance with a filename determined by you, say on a per-upload basis.