C# sharepoint 2007中的ULS日志

C# sharepoint 2007中的ULS日志,c#,.net,sharepoint,logging,sharepoint-2007,C#,.net,Sharepoint,Logging,Sharepoint 2007,是否有办法从wss或moss服务器场中的所有服务器获取ULS日志。我需要使用C#以编程方式获取日志。我可以从服务器场中的一台服务器获取日志,但我需要所有日志。感谢您的帮助。您可以使用ULS查看器: 或者您可以使用SPDiagnosticsService 从评论中编辑: 要直接读取文件,可以执行以下操作: try { // Create an instance of StreamReader to read from a file. // The

是否有办法从wss或moss服务器场中的所有服务器获取ULS日志。我需要使用C#以编程方式获取日志。我可以从服务器场中的一台服务器获取日志,但我需要所有日志。感谢您的帮助。

您可以使用ULS查看器:

或者您可以使用
SPDiagnosticsService

从评论中编辑:

要直接读取文件,可以执行以下操作:

   try 
    {
        // Create an instance of StreamReader to read from a file.
        // The using statement also closes the StreamReader.
        using (StreamReader sr = new StreamReader("FilePath:\\SharePointlogfile.uls")) 
        {
            string line;
            // Read and display lines from the file until the end of 
            // the file is reached.
            while ((line = sr.ReadLine()) != null) 
            {
                Console.WriteLine(line);
            }
        }
    }
    catch (Exception e) 
    {
        // Let the user know what went wrong.
        Console.WriteLine("The file could not be read:");
        Console.WriteLine(e.Message);
    }

问题是我需要以编程方式获取日志,而不需要工具。对于WSS2007,您最好的选择是使用SPDiagnosticsService类并应用于农场级别。如果您的程序可以访问服务器场中的所有服务器,您可以使用简单的StreamReader直接读取文件,并将其指向每个服务器的{SharePoint Root}\LOGS。我可以访问所有服务器,但您提供了代码行。我不知道如何直接读取文件。提前谢谢。@Alexander在代码中设置它,或者您可以有一个名为FilePath的列表,其中包含您的所有文件路径。我的主要问题是如何使用SPDiagnosticsService类获取文件路径。我相信这会解决我的问题。现在我正试图通过powershell命令Merge-SPLogFile来解决我的需要,我已经读过这篇文章,但它也不适合我。有什么想法吗