本文整理汇总了C#中LogSource类的典型用法代码示例。如果您正苦于以下问题:C# LogSource类的具体用法?C# LogSource怎么用?C# LogSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogSource类属于命名空间,在下文中一共展示了LogSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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();
}
}
示例3: Log
public static void Log(string message, LogType type, LogSource src)
{
if (OnLog != null)
{
OnLog(message, type, src);
}
}
示例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) { }
}
示例5: AutoFlushDefaultPropertyIsTrue
public void AutoFlushDefaultPropertyIsTrue()
{
string name = "name";
bool defaultAutoFlushProperty = true;
LogSource logSource = new LogSource(name);
Assert.AreEqual(defaultAutoFlushProperty, logSource.AutoFlush);
}
示例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];
}
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}
示例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());
}
示例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;
}
}
示例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);
}
示例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());
}
示例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);
}