1: <? xml version ="1.0" encoding ="utf-8" ? >
2: < configuration >
3: < configSections >
4: < section name ="loggingConfiguration" type ="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
5: < section name ="dataConfiguration" type ="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
6: </ configSections >
7: < loggingConfiguration name ="Logging Application Block" tracingEnabled ="true"
8: defaultCategory ="General" logWarningsWhenNoCategoriesMatch ="true" >
9: < listeners >
10: < add source ="Enterprise Library Logging" formatter ="Text Formatter"
11: log ="Application" machineName ="" listenerDataType ="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
12: traceOutputOptions ="None" filter ="All" type ="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
13: name ="Formatted EventLog TraceListener" />
14: </ listeners >
15: < formatters >
16: < add template ="Timestamp: {timestamp} Message: {message} Category: {category} Priority: {priority} EventId: {eventid} Severity: {severity} Title:{title} Machine: {machine} Application Domain: {appDomain} Process Id: {processId} Process Name: {processName} Win32 Thread Id: {win32ThreadId} Thread Name: {threadName} Extended Properties: {dictionary({key} - {value} )}"
17: type ="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
18: name ="Text Formatter" />
19: </ formatters >
20: < categorySources >
21: < add switchValue ="All" name ="General" >
22: < listeners >
23: < add name ="Formatted EventLog TraceListener" />
24: </ listeners >
25: </ add >
26: </ categorySources >
27: < specialSources >
28: < allEvents switchValue ="All" name ="All Events" />
29: < notProcessed switchValue ="All" name ="Unprocessed Category" />
30: < errors switchValue ="All" name ="Logging Errors & Warnings" >
31: < listeners >
32: < add name ="Formatted EventLog TraceListener" />
33: </ listeners >
34: </ errors >
35: </ specialSources >
36: </ loggingConfiguration >
37: </ configuration >
* This source code was highlighted with Source Code Highlighter .
using Microsoft.Practices.EnterpriseLibrary.Logging;
* This source code was highlighted with Source Code Highlighter .
class Program
{
static void Main( string [] args)
{
LogEntry entry = new LogEntry()
{
Message = "Hello Ent. Lib. Logging"
};
Logger.Write(entry);
}
}
* This source code was highlighted with Source Code Highlighter .
LogEntry entry = new LogEntry()
{
Message = "Hello Ent. Lib. Logging" ,
Severity = TraceEventType.Critical
};
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/71078/
All Articles