小编Chr*_*one的帖子

获取有关Windows服务的内部状态的信息

我有一个Windows服务,我用.NET C#编写.该服务将充当文件处理器.它只是查看File Created事件的目录,并将这些文件添加到队列中进行处理.一个单独的线程从队列中提取文件并处理它们.

我的问题是,是否有办法查询Windows服务以获得其"状态".我希望能够以某种方式查询服务,并查看当前在队列中等待的文件列表等.

我知道这可以通过/ proc文件系统在Linux中完成,我想知道Windows是否有类似的东西.任何提示/指示将不胜感激.

.net c# windows service state

6
推荐指数
1
解决办法
1411
查看次数

Logger和LogWriter之间的区别

我正在使用Microsoft Enterprise Library 5.0 Logging块,我想知道LogWriter和Logger类之间的区别.我有一些自定义跟踪侦听器,我已经构建用于我的日志记录,我想知道使用Logger与LogWriter是否会产生任何影响.

来自MSDN http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.logging.logwriter.aspx

要将日志消息写入默认配置,请使用Logger外观.如果需要使用自定义配置编写日志消息,则仅创建LogWriter的实例.

示例代码#1:

namespace ExampleOne
{
    using System;
    using System.Diagnostics;
    using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
    using Microsoft.Practices.EnterpriseLibrary.Logging;

    public class Program
    {
        private static LogWriter logger = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();

        public static void Main(string[] args)
        {
            try
            {
                throw new Exception("My test exception message");
            }
            catch (Exception ex)
            {
                LogEntry logEntry = new LogEntry();
                logEntry.Message = "Error: " + ex.ToString();
                logEntry.Categories.Add("General");
                logEntry.Severity = TraceEventType.Error;
                logger.Write(logEntry);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

示例代码#2:

namespace ExampleTwo    
{
    using System;
    using System.Diagnostics;
    using …
Run Code Online (Sandbox Code Playgroud)

logging customization tracelistener enterprise-library-5

5
推荐指数
2
解决办法
1万
查看次数