本文整理汇总了C#中LogSource类的典型用法代码示例。如果您正苦于以下问题:C# LogSource类的具体用法?C# LogSource怎么用?C# LogSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogSource类属于命名空间,在下文中一共展示了LogSource类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: FlatFileListenerWillFallbackIfNotPriviledgesToWrite
public void FlatFileListenerWillFallbackIfNotPriviledgesToWrite()
{
string fileName = @"trace.log";
string fullPath = String.Format(@"{0}\{1}", Directory.GetCurrentDirectory(), fileName);
File.Delete(fileName);
FileIOPermission fileIOPerm1 = new FileIOPermission(PermissionState.None);
fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, fullPath);
fileIOPerm1.PermitOnly();
try
{
FlatFileTraceListener listener = new FlatFileTraceListener(fileName, "---header---", "***footer***",
new TextFormatter("DUMMY{newline}DUMMY"));
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
source.TraceData(TraceEventType.Error, 0,
new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null));
listener.Dispose();
}
catch (SecurityException)
{
FileIOPermission.RevertAll();
throw;
}
}
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:28,代码来源:FlatFileTraceListenerFixture.2008.cs
示例2: SendLogEntry
void SendLogEntry(WmiTraceListener listener,
LogEntry logEntry)
{
ManagementScope scope = new ManagementScope(@"\\." + wmiPath);
scope.Options.EnablePrivileges = true;
StringBuilder sb = new StringBuilder("SELECT * FROM ");
sb.Append("LogEntryV20");
string query = sb.ToString();
EventQuery eq = new EventQuery(query);
using (ManagementEventWatcher watcher = new ManagementEventWatcher(scope, eq))
{
watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
watcher.Start();
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 1, logEntry);
BlockUntilWMIEventArrives();
watcher.Stop();
}
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:25,代码来源:WMIListenerFixture.cs
示例3: Log
public static void Log(string message, LogType type, LogSource src)
{
if (OnLog != null)
{
OnLog(message, type, src);
}
}
开发者ID:TaFinalDestination,项目名称:MCSharp,代码行数:7,代码来源:Logger.cs
示例4: UpdateLog
public void UpdateLog(string message, LogType type, LogSource src)
{
Color clr = consoleLogTextbox.ForeColor;
try
{
if ((LogType.Warning & type) == type)
clr = Color.Yellow;
else if ((LogType.OpChat & type) == type || (LogType.GlobalChat & type) == type || (LogType.IRCChat & type) == type || (LogType.GlobalChat & type) == type)
clr = Color.White;
else if ((LogType.Error & type) == type || (LogType.FatalError & type) == type || (LogType.ErrorMessage & type) == type)
clr = Color.Red;
message = Environment.NewLine + "[" + DateTime.Now.ToString("hh:mm:ss tt") + "]"
+ "[" + Enum.GetName(typeof(LogType), type).Substring(0, 1) + "]"
+ " - " + message;
if ((LogTypes & type) == type || ((LogType.Debug & type) == type && MCSharp.Properties.DebugEnabled))
{
if (this.consoleLogTextbox.InvokeRequired)
{
AppendTextCallback d = new AppendTextCallback(Log);
this.Invoke(d, new object[] { message, clr });
}
else
{
Log(message, clr);
}
}
}
catch (Exception) { }
}
开发者ID:ZakAmirz,项目名称:MCSharp,代码行数:31,代码来源:mainForm.cs
示例5: AutoFlushDefaultPropertyIsTrue
public void AutoFlushDefaultPropertyIsTrue()
{
string name = "name";
bool defaultAutoFlushProperty = true;
LogSource logSource = new LogSource(name);
Assert.AreEqual(defaultAutoFlushProperty, logSource.AutoFlush);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:9,代码来源:TraceSourceFixture.cs
示例6:
/// <summary>
/// Gets the <see cref="Delta.CertXplorer.Logging.ILogService"/> with the specified source.
/// </summary>
/// <value></value>
public ILogService this[LogSource source]
{
get
{
if ((source != null) && (source.Name == currentSourceName))
return this;
return this[source.Name];
}
}
开发者ID:sagar1589,项目名称:Delta.Cryptography,代码行数:13,代码来源:Log4NetService.MultiSource.cs
示例7: SetUp
public void SetUp()
{
logWriter = EnterpriseLibraryFactory.BuildUp<LogWriter>();
MockTraceListener.Reset();
ErrorsMockTraceListener.Reset();
emptyTraceSource = new LogSource("none");
if (emptyTraceSource.Listeners.Count == 1)
emptyTraceSource.Listeners.RemoveAt(0);
}
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:10,代码来源:LogDistributorFixture.cs
示例8: SetUp
public void SetUp()
{
AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
logWriter = new LogWriterFactory().Create();
MockTraceListener.Reset();
ErrorsMockTraceListener.Reset();
emptyTraceSource = new LogSource("none", Enumerable.Empty<TraceListener>(), SourceLevels.All);
Assert.IsFalse(emptyTraceSource.Listeners.Any());
}
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:11,代码来源:LogDistributorFixture.cs
示例9: SetUp
public void SetUp()
{
AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
logWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
MockTraceListener.Reset();
ErrorsMockTraceListener.Reset();
emptyTraceSource = new LogSource("none");
if (emptyTraceSource.Listeners.Count == 1)
emptyTraceSource.Listeners.RemoveAt(0);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:12,代码来源:LogDistributorFixture.cs
示例10: ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists
public void ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
{
LogEntry testEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
StringWriter writer = new StringWriter();
FormattedEventLogTraceListener listener = new FormattedEventLogTraceListener(CommonUtil.EventLogSourceName, CommonUtil.EventLogNameCustom, null);
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
source.TraceData(TraceEventType.Error, 1, testEntry);
Assert.AreEqual(testEntry.ToString(), CommonUtil.GetLastEventLogEntryCustom());
}
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:12,代码来源:FormattedEventLogListenerFixture.cs
示例11: FormattedListenerWillUseFormatterIfExists
public void FormattedListenerWillUseFormatterIfExists()
{
StringWriter writer = new StringWriter();
FormattedTextWriterTraceListener listener = new FormattedTextWriterTraceListener(writer, new TextFormatter("DUMMY{newline}DUMMY"));
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 0, new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null));
Assert.AreEqual("DUMMY" + Environment.NewLine + "DUMMY", writer.ToString());
}
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:12,代码来源:FormattedTextWriterListenerFixture.cs
示例12: Write
internal static void Write(LogSource Source, Exception Ex)
{
if (Ex == null || !EnableLogging) return;
if (Ex.InnerException != null) Ex = Ex.InnerException;
try
{
if (!Directory.Exists(ApplicationSettings.DataPath + "log\\"))
Directory.CreateDirectory(ApplicationSettings.DataPath + "log\\");
LogFilePath = ApplicationSettings.DataPath + "log\\LOG." + DateTime.Today.ToString("yyyy-MM-dd") + ".EXCEPTION";
LogStream = new FileStream(LogFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
Log = new StreamWriter(LogStream, Encoding.UTF8);
StringBuilder SB = new StringBuilder();
if (LogStream.Length < 21)
SB.AppendLine("<ERRORLOG>");
else
LogStream.Position = LogStream.Length - 13;
SB.AppendLine(" <LOG TIME=\"{0}\" SOURCE=\"{1}\">");
SB.AppendLine(" <EXCEPTION>{2}</EXCEPTION>");
SB.AppendLine(" <MESSAGE>{3}</MESSAGE>");
SB.AppendLine(" <SOURCE>{4}</SOURCE>");
SB.AppendLine(" <STACK>{5}</STACK>");
SB.AppendLine(" <TARGETSITE>{6}</TARGETSITE>");
SB.AppendLine(" </LOG>");
SB.AppendLine("</ERRORLOG>"); // End the xml file
Log.Write(
string.Format(SB.ToString(),
DateTime.Now.ToString("HH:mm:ss"),
Source.ToString(),
Ex.ToString(),
Ex.Message,
Ex.Source,
Ex.StackTrace,
Ex.TargetSite.Name));
SB = null;
}
catch (Exception Exn)
{ }
finally
{
if (Log != null) Log.Close(); Log = null;
if (LogStream != null) LogStream.Close(); LogStream = null;
}
}
开发者ID:solunar66,项目名称:AdPlayer,代码行数:52,代码来源:LogWriter.cs
示例13: LogSourceDoesAutoFlush
public void LogSourceDoesAutoFlush()
{
MockFlushSensingTraceListener traceListener = new MockFlushSensingTraceListener();
List<TraceListener> listeners = new List<TraceListener>(1);
listeners.Add(traceListener);
// Use the default configuration
LogSource logSource = new LogSource("name", listeners, SourceLevels.All, true);
logSource.TraceData(TraceEventType.Critical, 0, CommonUtil.GetDefaultLogEntry());
Assert.AreEqual(1, traceListener.flushCalls);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:13,代码来源:TraceSourceFixture.cs
示例14: ListenerWillUseFormatterIfExists
public void ListenerWillUseFormatterIfExists()
{
StringWriter writer = new StringWriter();
FormattedEventLogTraceListener listener = new FormattedEventLogTraceListener(CommonUtil.EventLogSourceName, CommonUtil.EventLogNameCustom, new TextFormatter("DUMMY{newline}DUMMY"));
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
LogEntry logEntry = CommonUtil.GetDefaultLogEntry();
source.TraceData(TraceEventType.Error, 1, logEntry);
Assert.AreEqual("DUMMY" + Environment.NewLine + "DUMMY", CommonUtil.GetLastEventLogEntryCustom());
}
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:14,代码来源:FormattedEventLogListenerFixture.cs
示例15: LogSourceDoesNotAutoFlush
public void LogSourceDoesNotAutoFlush()
{
MockFlushSensingTraceListener traceListener = new MockFlushSensingTraceListener();
List<TraceListener> listeners = new List<TraceListener>(1);
listeners.Add(traceListener);
LogSource logSource = new LogSource("name", listeners, SourceLevels.All);
logSource.AutoFlush = false;
logSource.TraceData(TraceEventType.Critical, 0, CommonUtil.GetDefaultLogEntry());
Assert.AreEqual(0, traceListener.flushCalls);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:14,代码来源:TraceSourceFixture.cs
示例16: ListenerWithHeaderAndFooterWillUseFormatterIfExists
public void ListenerWithHeaderAndFooterWillUseFormatterIfExists()
{
File.Delete("tracewithheaderandfooter.log");
FlatFileTraceListener listener = new FlatFileTraceListener("tracewithheaderandfooter.log", "--------header------", "=======footer===========", new TextFormatter("DUMMY{newline}DUMMY"));
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
source.TraceData(TraceEventType.Error, 0, new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null));
listener.Dispose();
string strFileContents = GetFileContents("tracewithheaderandfooter.log");
Assert.AreEqual("--------header------" + Environment.NewLine + "DUMMY" + Environment.NewLine + "DUMMY" + Environment.NewLine + "=======footer===========" + Environment.NewLine, strFileContents);
}
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:15,代码来源:FlatFileTraceListenerFixture.cs
示例17: ShouldLogApplyingLog
public void ShouldLogApplyingLog()
{
using (StringWriter writer = new StringWriter())
{
FormattedTextWriterTraceListener listener = new FormattedTextWriterTraceListener(writer, new TextFormatter("DUMMY{newline}DUMMY"));
listener.Filter = new EventTypeFilter(SourceLevels.Error);
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 0, new LogEntry("message", "cat1", 0, 0, TraceEventType.Critical, "title", null));
Assert.AreNotEqual(0, writer.ToString().Length);
}
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:16,代码来源:FormattedTextWriterListenerFixture.cs
示例18: FormattedListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists
public void FormattedListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
{
LogEntry testEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
StringWriter writer = new StringWriter();
FormattedTextWriterTraceListener listener = new FormattedTextWriterTraceListener(writer);
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 0, testEntry);
string writtenData = writer.ToString();
string testEntryToString = testEntry.ToString();
Assert.IsTrue(-1 != writtenData.IndexOf(testEntryToString));
}
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:16,代码来源:FormattedTextWriterListenerFixture.cs
示例19: ListenerWillUseFormatterIfExists
public void ListenerWillUseFormatterIfExists()
{
MockEmailTraceListener listener = new MockEmailTraceListener(new TextFormatter("DUMMY\r\nTime:{timestamp}\r\nMessage:{message}DUMMY"));
LogEntry entry = new LogEntry("Test Message", "Test Category", 42, 999, TraceEventType.Information, "Test Title", null);
DateTime messageTimestamp = DateTime.UtcNow;
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
source.TraceData(TraceEventType.Error, 0, entry);
Assert.AreEqual("EntLib-Logging: Information has occurred", lastMailMessageSent.Subject);
Assert.AreEqual("[email protected]", lastMailMessageSent.To[0].Address);
Assert.AreEqual("[email protected]", lastMailMessageSent.To[1].Address);
Assert.AreEqual("[email protected]", lastMailMessageSent.From.Address);
AssertContainsSubstring(lastMailMessageSent.Body, messageTimestamp.ToString());
}
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:17,代码来源:EmailTraceListenerFixture.cs
示例20: ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists
public void ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
{
LogEntry testLogEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
StreamWriter writer = new StreamWriter("trace.log");
FlatFileTraceListener listener = new FlatFileTraceListener(writer);
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
source.TraceData(TraceEventType.Error, 0, testLogEntry);
listener.Dispose();
string strFileContents = GetFileContents("trace.log");
string testLogEntryAsString = testLogEntry.ToString();
Assert.IsTrue(-1 != strFileContents.IndexOf(testLogEntryAsString));
}
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:17,代码来源:FlatFileTraceListenerFixture.cs
注:本文中的LogSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论