The ULS Viewer is a wonderful tool that all SharePoint admins absolutely should have on their servers. There is no other utility that is as quick and easy to use for ULS log viewing – and more importantly, it’s free!
I am helping develop some custom Remote Blob Storage services for SQL Server 2008 and SharePoint 2010 (Stepwise Enterprise Storage – imminent release!) and I wanted to be able to use the ULS log viewer, but I didn’t want to spam the SharePoint logs and our services don’t need to be installed on SharePoint itself.
I set up the Microsoft Enterprise Library Logging Application Block and the Rolling Flat File Trace Listener to do the job for me. The rolling flat file trace listener automatically creates a new file when the current file meets certain criteria, such as size or age. Note the hard-coded [fileName="MyService-20200101-0000.log"], this is required because the ULS Log Viewer is hard-coded to look for files matching the format *-????????-?????.log i.e. MyService-yyyymmdd-HHmmss.log. You can set this to something different, but I thought this would be fairly safe.
First I added a Rolling Flat File Trace Listener:
<add name="Rolling Flat File Trace Listener" fileName="MyService-20200101-0000.log" footer="" formatter="ULS SingleLine Text Formatter" header="" rollFileExistsBehavior="Increment" rollInterval="Day" rollSizeKB="2048" timeStampPattern="-yyyyMMdd-HHmm" traceOutputOptions="None" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
then I need to make sure the format for the output was correct. ULS wants the following fields supplied:
•Timestamp: Equivalent to the “TimeGenerated” field in the “Application” event Log
•Process: the image name of the process logging its activity followed by its process ID (PID) between parentheses.
•TID: Thread ID
•Area: This maps the “Source” field in the “Application” event Log
•Category: this maps the “Category” field in the “Application” event Log
•EventID: A unique internal Event ID (which you can generate)
•Level: Logging level i.e. Information, Verbose, Error, etc.
•Message: Text message
•Correlation: may contain a link to the the EventID of another logged event, which again you can generate
so this is the formatter I used:
<add
template="{timestamp(local:dd/MM/yyyy HH:mm:ss.fff)} {tab}{appDomain} {tab}{win32ThreadId} {tab}{source} {tab}{category} {tab}{eventid} {tab}{severity} {tab}{message} - {priority} - {dictionary({key} - {value}|)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="ULS SingleLine Text Formatter" />

