在运行时更改侦听器属性
我正在使用 Ent Lib 5。我有一个事件日志监听器,其 Source 属性当前设置为我们应用程序套件的通用名称。
该配置文件与多个项目链接/共享(说来话长,不会改变)。
我们仍然希望每个应用程序将其自己的源名称放入事件日志中以唯一标识它...我如何在运行时更改源名称?
我可以轻松更改有关实际日志事件本身的任何内容,但我想更改每个应用程序的侦听器源属性。
希望这是有道理的
更新: 这是我们正在使用的配置设置...它是我想在运行时更改的 SOURCE 属性。
添加名称=“格式化的EventLog常规”类型=“Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging,版本= 5.0.0.0,文化=中性,PublicKeyToken = 31bf3856ad364e35”listenerDataType =“Microsoft. Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData、Microsoft.Practices.EnterpriseLibrary.Logging、版本=5.0.0.0、文化=中性、PublicKeyToken=31bf3856ad364e35"formatter="文本格式化程序"traceOutputOptions="无"filter="全部"machineName= “。”源=“运行时更改”日志=“应用程序”
I am using Ent Lib 5. I have a Event Log Listener with the Source attribute currently set to a generic name for our suite of applications.
This configuration file is linked/shared with several projects (long story and will not change).
We would still like each application to put its own Source name in the event log to uniquely identify it...how do I go about changing the Source name at run time?
I can easily change anything I want about the actual log event itself but I want to change the listener source attribute for each app.
Hopefully this makes sense
UPDATE:
Here is the config setting that we are using...it is the SOURCE attribute that I want to change at runtime.
add name="Formatted EventLog General" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" formatter="Text Formatter" traceOutputOptions="None" filter="All" machineName="." source="CHANGE AT RUNTIME" log="Application"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以要求记录器写入特定类别。
下面的示例创建了 2 个类别 - AppOne、AppTwo。
然后我添加了两个跟踪侦听器 - AppOneListener(绑定到 AppOne 类别)和 AppTwoListener(绑定到 AppTwo Listener)。
当你想记录日志时,在源代码中指定类别。
下面是配置:
查看categorySources 部分和listeners 部分。
You can ask the Logger to write to a specific category.
The sample below, created a 2 categories - AppOne, AppTwo.
And then I've added two trace listeners - AppOneListener (bound to AppOne category) and AppTwoListener (bound to AppTwo Listener).
And in source code when you want to log, specify the category.
Below is the configuration:
Look at the categorySources section and listeners section.