本文整理汇总了C#中LogWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# LogWriter.Write方法的具体用法?C# LogWriter.Write怎么用?C# LogWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogWriter
的用法示例。
在下文中一共展示了LogWriter.Write方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
/// <summary>
/// Writes the given log entry to the log.
/// </summary>
/// <param name="entry">The log entry to write.</param>
public void Write(LogEntry entry)
{
if (IsTracingEnabled())
{
LogWriter writer = new LogWriter(loggingConfigurationView.ConfigurationContext);
writer.Write(entry);
}
}
示例2: MissingCategoriesWarningIsLoggedIfLogWarningFlagIsTrue
public void MissingCategoriesWarningIsLoggedIfLogWarningFlagIsTrue()
{
LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
LogSource failingTraceSource = new LogSource("logging", SourceLevels.All);
failingTraceSource.Listeners.Add(new MockTraceListener());
LogSource loggingTraceSource = new LogSource("logging2", SourceLevels.All);
loggingTraceSource.Listeners.Add(new MockTraceListener());
LogWriter writer =
new LogWriter(new ILogFilter[0],
new LogSource[] { failingTraceSource, loggingTraceSource },
emptyTraceSource,
emptyTraceSource,
errorsTraceSource,
"default",
false,
true);
LogEntry logEntry = new LogEntry();
logEntry.Message = originalMessage;
logEntry.Severity = TraceEventType.Critical;
logEntry.Categories = new string[] { "logging", "logging2", "logging3" };
writer.Write(logEntry);
writer.Dispose();
Assert.AreEqual(1, ErrorsMockTraceListener.Entries.Count);
Assert.AreEqual(TraceEventType.Error, ErrorsMockTraceListener.LastEntry.Severity);
Assert.IsTrue(MatchTemplate(ErrorsMockTraceListener.LastEntry.Message, Resources.MissingCategories));
Assert.AreEqual(2, MockTraceListener.Entries.Count);
Assert.AreSame(logEntry, MockTraceListener.LastEntry);
}
示例3: NoErrorsWhileSendingToTraceSourceOnlyLogsOriginalMessageToCategoryTraceSources
public void NoErrorsWhileSendingToTraceSourceOnlyLogsOriginalMessageToCategoryTraceSources()
{
LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
LogSource failingTraceSource = new LogSource("logging", SourceLevels.All);
failingTraceSource.Listeners.Add(new MockTraceListener());
LogSource loggingTraceSource = new LogSource("logging2", SourceLevels.All);
loggingTraceSource.Listeners.Add(new MockTraceListener());
LogWriter writer =
new LogWriter(new ILogFilter[0],
new LogSource[] { failingTraceSource, loggingTraceSource },
errorsTraceSource,
"default");
LogEntry logEntry = new LogEntry();
logEntry.Message = originalMessage;
logEntry.Severity = TraceEventType.Critical;
logEntry.Categories = new string[] { "logging", "logging2" };
writer.Write(logEntry);
writer.Dispose();
Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
Assert.AreEqual(2, MockTraceListener.Entries.Count);
Assert.AreSame(logEntry, MockTraceListener.LastEntry);
}
示例4: ErrorWhileSendingToTraceSourceLogsWarningAndLogsOriginalMessageToNonFailingTraceSources
public void ErrorWhileSendingToTraceSourceLogsWarningAndLogsOriginalMessageToNonFailingTraceSources()
{
LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
LogSource failingTraceSource = new LogSource("failing", SourceLevels.All);
failingTraceSource.Listeners.Add(new ExceptionThrowingMockTraceListener());
LogSource loggingTraceSource = new LogSource("logging", SourceLevels.All);
loggingTraceSource.Listeners.Add(new MockTraceListener());
LogWriter writer =
new LogWriter(new ILogFilter[0],
new LogSource[] { failingTraceSource, loggingTraceSource },
errorsTraceSource,
"default");
LogEntry logEntry = new LogEntry();
logEntry.Message = originalMessage;
logEntry.Severity = TraceEventType.Critical;
logEntry.Categories = new string[] { "failing", "logging" };
writer.Write(logEntry);
writer.Dispose();
Assert.AreEqual(1, ErrorsMockTraceListener.Entries.Count);
Assert.AreEqual(TraceEventType.Error, ErrorsMockTraceListener.LastEntry.Severity);
Assert.IsTrue(MatchTemplate(ErrorsMockTraceListener.LastEntry.Message, Resources.TraceSourceFailed));
Assert.AreEqual(1, MockTraceListener.Entries.Count);
Assert.AreSame(logEntry, MockTraceListener.LastEntry);
}
示例5: WmiFiredWhenDeliveryToErrorSourceFails
public void WmiFiredWhenDeliveryToErrorSourceFails()
{
TraceListener badTraceListener = new BadTraceListener(new Exception("test exception"));
LogSource badSource = new LogSource("badSource");
badSource.Listeners.Add(badTraceListener);
Dictionary<string, LogSource> logSources = new Dictionary<string,LogSource>();
logSources.Add("foo", badSource);
LogWriter writer = new LogWriter(new List<ILogFilter>(), logSources, badSource, "foo");
new ReflectionInstrumentationBinder().Bind(writer.GetInstrumentationEventProvider(), new LoggingInstrumentationListener(false, false, true));
using (WmiEventWatcher eventListener = new WmiEventWatcher(1))
{
writer.Write(CommonUtil.GetDefaultLogEntry());
eventListener.WaitForEvents();
Assert.AreEqual(1, eventListener.EventsReceived.Count);
Assert.AreEqual("LoggingFailureLoggingErrorEvent", eventListener.EventsReceived[0].ClassPath.ClassName);
string exceptionMessage = (string) eventListener.EventsReceived[0].GetPropertyValue("ExceptionMessage");
Assert.IsTrue(-1 != exceptionMessage.IndexOf("test exception"));
Assert.IsNotNull(eventListener.EventsReceived[0].GetPropertyValue("ErrorMessage"));
}
}
示例6: EventLogWrittenWhenDeliveryToErrorSourceFails
public void EventLogWrittenWhenDeliveryToErrorSourceFails()
{
TraceListener badTraceListener = new BadTraceListener(new Exception("test exception"));
LogSource badSource = new LogSource("badSource");
badSource.Listeners.Add(badTraceListener);
Dictionary<string, LogSource> logSources = new Dictionary<string, LogSource>();
logSources.Add("foo", badSource);
LogWriter writer = new LogWriter(new List<ILogFilter>(), logSources, badSource, "foo");
new ReflectionInstrumentationBinder().Bind(writer.GetInstrumentationEventProvider(), new LoggingInstrumentationListener(false, true, false));
writer.Write(CommonUtil.GetDefaultLogEntry());
string lastEventLogEntry = CommonUtil.GetLastEventLogEntry();
Assert.IsTrue(-1 != lastEventLogEntry.IndexOf("test exception"));
}
示例7: LogStatsCombineCategory
// There may be multiple containers but combine all containers under the one category.
private void LogStatsCombineCategory(string category, string logDir, string logPrefix, int logFileTime, bool logFlushWrites, List<string> fields)
{
SortedDictionary<string, SortedDictionary<string, Stat>> categoryStats;
LogWriter connWriter = null;
Dictionary<string, string> outputValues = new Dictionary<string, string>();
if (StatsManager.TryGetStatsForCategory(category, out categoryStats))
{
foreach (string container in categoryStats.Keys)
{
SortedDictionary<string, Stat> containerStats = categoryStats[container];
if (container == "network")
{
// Super special kludge that adds the field headers for the network stats.
// This is done this way because the name includes the name of the NIC
// and there could be more than one NIC.
foreach (Stat rStat in containerStats.Values)
{
if (!serverStatFields.Contains(rStat.Name))
{
serverStatFields.Add(rStat.Name);
}
}
}
foreach (Stat rStat in containerStats.Values)
{
outputValues.Add(rStat.Name, rStat.Value.ToString());
}
}
// Get the log file writer for this connection and create one if necessary.
string loggerName = category;
if (!StatLoggers.TryGetValue(loggerName, out connWriter))
{
string headr = logPrefix;
headr = headr.Replace("%CATEGORY%", category);
headr = headr.Replace("%REGIONNAME%", RegionName);
connWriter = new LogWriter(logDir, headr, logFileTime, logFlushWrites);
StatLoggers.Add(loggerName, connWriter);
if (LogRegionIncludeTitleLine)
{
StringBuilder bufft = new StringBuilder();
bufft.Append("Category");
bufft.Append(",");
bufft.Append("RegionName");
foreach (string fld in fields)
{
bufft.Append(",");
bufft.Append(fld);
}
connWriter.Write(bufft.ToString());
}
}
StringBuilder buff = new StringBuilder();
buff.Append(category);
buff.Append(",");
buff.Append(RegionName);
foreach (string fld in fields)
{
buff.Append(",");
buff.Append(outputValues.ContainsKey(fld) ? outputValues[fld] : "");
}
connWriter.Write(buff.ToString());
}
}
示例8: LogStats
private void LogStats(string category, string logDir, string logPrefix, int logFileTime, bool logFlushWrites, List<string> fields)
{
SortedDictionary<string, SortedDictionary<string, Stat>> categoryStats;
if (StatsManager.TryGetStatsForCategory(category, out categoryStats))
{
foreach (string container in categoryStats.Keys)
{
SortedDictionary<string, Stat> containerStats = categoryStats[container];
LogWriter connWriter = null;
Dictionary<string, string> outputValues = new Dictionary<string, string>();
foreach (Stat rStat in containerStats.Values)
{
// Get the log file writer for this connection and create one if necessary.
if (connWriter == null)
{
string loggerName = category + "/" + container;
if (!StatLoggers.TryGetValue(loggerName, out connWriter))
{
string headr = logPrefix;
headr = headr.Replace("%CATEGORY%", category);
headr = headr.Replace("%CONTAINER%", container);
headr = headr.Replace("%REGIONNAME%", RegionName);
connWriter = new LogWriter(logDir, headr, logFileTime, logFlushWrites);
StatLoggers.Add(loggerName, connWriter);
if (LogRegionIncludeTitleLine)
{
StringBuilder bufft = new StringBuilder();
bufft.Append("Category");
bufft.Append(",");
bufft.Append("Container");
foreach (string fld in fields)
{
bufft.Append(",");
bufft.Append(fld);
}
connWriter.Write(bufft.ToString());
}
}
}
outputValues.Add(rStat.Name, rStat.Value.ToString());
}
StringBuilder buff = new StringBuilder();
buff.Append(category);
buff.Append(",");
buff.Append(container);
foreach (string fld in fields)
{
buff.Append(",");
buff.Append(outputValues.ContainsKey(fld) ? outputValues[fld] : "");
}
connWriter.Write(buff.ToString());
}
}
}
示例9: LogConnectorStats
private void LogConnectorStats()
{
List<string> fields = new List<string>
{ "Msgs_Sent", "Msgs_Rcvd", "Bytes_Sent", "Bytes_Rcvd",
"Msgs_Sent_Per_Sec", "Msgs_Rcvd_Per_Sec", "Bytes_Sent_Per_Sec", "Bytes_Rcvd_Per_Sec",
"Queued_Msgs",
"UpdatedProperties_Sent", "UpdatedProperties_Rcvd",
"NewObject_Sent", "NewObject_Rcvd", "NewPresence_Sent", "NewPresence_Rcvd"
};
// Milliseconds since the last time we collected statistics
int msSinceLast = Util.EnvironmentTickCountSubtract(lastStatTime);
SortedDictionary<string, SortedDictionary<string, Stat>> DSGStats;
if (StatsManager.TryGetStatsForCategory(DSGDetailCategory, out DSGStats))
{
foreach (string container in DSGStats.Keys)
{
LogWriter connWriter = null;
SyncConnectorStat lastStat = null;
Dictionary<string, double> outputValues = new Dictionary<string, double>();
SortedDictionary<string, Stat> containerStats = DSGStats[container];
foreach (Stat aStat in containerStats.Values)
{
// Select out only the SyncConnector stats.
SyncConnectorStat connStat = aStat as SyncConnectorStat;
if (connStat != null)
{
lastStat = connStat; // remember one of the stats for line output info
outputValues.Add(connStat.Name, connStat.Value);
}
}
// Get the log file writer for this connection and create one if necessary.
if (lastStat != null)
{
if (!ConnectionLoggers.TryGetValue(container, out connWriter))
{
string headr = LogSyncConnectorFilenamePrefix;
headr = headr.Replace("%CONTAINER%", container);
headr = headr.Replace("%REGIONNAME%", lastStat.RegionName);
headr = headr.Replace("%CONNECTIONNUMBER%", lastStat.ConnectorNum.ToString());
headr = headr.Replace("%THISACTOR%", lastStat.MyActorID);
headr = headr.Replace("%OTHERSIDEACTOR%", lastStat.OtherSideActorID);
headr = headr.Replace("%OTHERSIDEREGION%", lastStat.OtherSideRegionName);
headr = headr.Replace("%MESSAGETYPE%", lastStat.MessageType);
connWriter = new LogWriter(LogSyncConnectorDirectory, headr, LogSyncConnectorFileTimeMinutes, LogSyncConnectorFlushWrites);
ConnectionLoggers.Add(container, connWriter);
if (LogSyncConnectorIncludeTitleLine)
{
StringBuilder bufft = new StringBuilder();
bufft.Append("Region");
bufft.Append(",");
bufft.Append("SyncConnNum");
bufft.Append(",");
bufft.Append("ActorID");
bufft.Append(",");
bufft.Append("OtherSideActorID");
bufft.Append(",");
bufft.Append("OtherSideRegionName");
foreach (string fld in fields)
{
bufft.Append(",");
bufft.Append(fld);
}
connWriter.Write(bufft.ToString());
}
}
LastStatValues lastValues;
if (!m_lastStatValues.TryGetValue(container, out lastValues))
{
lastValues = new LastStatValues();
m_lastStatValues.Add(container, lastValues);
}
// Compute some useful values
ComputePerSecond("Msgs_Sent", "Msgs_Sent_Per_Sec", ref outputValues, ref lastValues.lastMsgs_Sent, msSinceLast);
ComputePerSecond("Msgs_Rcvd", "Msgs_Rcvd_Per_Sec", ref outputValues, ref lastValues.lastMsgs_Rcvd, msSinceLast);
ComputePerSecond("Bytes_Sent", "Bytes_Sent_Per_Sec", ref outputValues, ref lastValues.lastBytes_Sent, msSinceLast);
ComputePerSecond("Bytes_Rcvd", "Bytes_Rcvd_Per_Sec", ref outputValues, ref lastValues.lastBytes_Rcvd, msSinceLast);
StringBuilder buff = new StringBuilder();
buff.Append(lastStat.RegionName);
buff.Append(",");
buff.Append(lastStat.ConnectorNum.ToString());
buff.Append(",");
buff.Append(lastStat.MyActorID);
buff.Append(",");
buff.Append(lastStat.OtherSideActorID);
buff.Append(",");
buff.Append(lastStat.OtherSideRegionName);
foreach (string fld in fields)
{
buff.Append(",");
buff.Append(outputValues.ContainsKey(fld) ? outputValues[fld].ToString() : "");
}
//.........这里部分代码省略.........
示例10: WriteTraceMessage
private void WriteTraceMessage(string message, string entryTitle)
{
if (IsTracingEnabled())
{
Hashtable extendedProperties = new Hashtable();
LogEntry entry = new LogEntry(message, Tracer.categoryStack.Peek(), priority, eventId, severity, entryTitle, extendedProperties);
LogWriter writer = new LogWriter(context);
writer.Write(entry);
}
}
示例11: Invoke
public async Task Invoke(HttpContext context)
{
if (!IsImageRequest(context))
{
// move to the next request here?
await _next.Invoke(context);
return;
}
try
{
var sb = new StringBuilder();
sb.AppendLine("=====================================================================================================");
sb.AppendLine("Date/Time: " + DateTime.UtcNow.ToString("M/d/yyyy hh:mm tt"));
int width = 0;
int.TryParse(context.Request.Query["width"], out width);
int height = 0;
int.TryParse(context.Request.Query["height"], out height);
var inputPath = _appEnvironment.ApplicationBasePath + "/wwwroot" + context.Request.Path;
using (var inputStream = File.OpenRead(inputPath))
{
sb.AppendLine("Input Path: " + inputPath);
sb.AppendLine("Querystring Dimensions: " + width.ToString() + "x" + height.ToString());
var sw = new Stopwatch();
sw.Start();
var image = new Image(inputStream);
if (image.Width > image.Height && width != 0)
height = (125 * image.Height) / image.Width;
if (image.Height > image.Width && height != 0)
width = (125 * image.Width) / image.Height;
sw.Stop();
sb.AppendLine("Original Dimensions: " + image.Width.ToString() + "x" + image.Height.ToString());
sb.AppendLine("Output Dimensions: " + width.ToString() + "x" + height.ToString());
sb.AppendLine("Image Read Time in Seconds: " + sw.Elapsed.TotalSeconds.ToString());
// write directly to the body output stream
using (var outputStream = new MemoryStream())
{
sw.Restart();
image.Resize(width, height)
.Save(outputStream);
var bytes = outputStream.ToArray();
sw.Stop();
sb.AppendLine("Image Processing Time in Seconds: " + sw.Elapsed.TotalSeconds.ToString());
//context.Response.Body.Write(bytes, 0, bytes.Length);
await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
}
//// the following approach will write to disk then serve the image
////var inputPath = _appEnvironment.ApplicationBasePath + "/wwwroot" + context.Request.Path;
//var outputPath = _appEnvironment.ApplicationBasePath + "/Uploads/" + Path.GetFileName(context.Request.Path);
//using (var outputStream = File.OpenWrite(outputPath))
//{
// image.Resize(width, height)
// .Save(outputStream);
//}
//var bytes = File.ReadAllBytes(outputPath);
//await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
}
//var logFilePath = _appEnvironment.ApplicationBasePath + "/Logs/ThumbnailLog-" + DateTime.UtcNow.ToString("yyyy-MM-dd-hh-mm-ss") + ".txt";
var logFilePath = _appEnvironment.ApplicationBasePath + "/Logs/ThumbnailLog.txt";
var logWriter = new LogWriter(logFilePath);
logWriter.Write(sb.ToString());
}
catch (Exception ex)
{
var logFilePath = _appEnvironment.ApplicationBasePath + "/Logs/Exceptions.txt";
var logWriter = new LogWriter(logFilePath);
logWriter.WriteLine("=====================================================================================================");
logWriter.WriteLine(ex.ToString());
}
//await _next.Invoke(context);
}
示例12: WndProc
/// <summary>
/// WndProc
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
LogWriter logWriter = new LogWriter(@"C:\log\MyTextbox.txt");
logWriter.Write(m.ToString());
IntPtr hIMC;
switch (m.Msg)
{
case NativeMethods.WM_CHAR:
hIMC = NativeMethods.ImmGetContext(this.Handle);
if (NativeMethods.ImmGetOpenStatus(hIMC) == 0)
{
char chr = Convert.ToChar(m.WParam.ToInt32() & 0xff);
Insert(chr.ToString());
// caret.SetPos(caret.GetPos().X + , caret.GetPos().Y);
}
NativeMethods.ImmReleaseContext(this.Handle, hIMC);
Invalidate();
break;
case NativeMethods.WM_IME_STARTCOMPOSITION:
hIMC = NativeMethods.ImmGetContext(this.Handle);
// ImmSetCompositionWindowとImmSetCandidateWindowがしっかり機能しているのかがイマイチ分からない。
// 変換ウィンドウの位置を設定
NativeMethods.COMPOSITIONFORM cf = new NativeMethods.COMPOSITIONFORM();
cf.dwStyle = NativeMethods.CFS_POINT;
cf.ptCurrentPos = new Point(100, 0);
cf.rcArea = new Rectangle();
NativeMethods.ImmSetCompositionWindow(hIMC, ref cf);
// 候補文字ウィンドウの位置調整を行う
NativeMethods.CANDIDATEFORM lpCandidate = new NativeMethods.CANDIDATEFORM();
lpCandidate.dwIndex = 0;
lpCandidate.dwStyle = NativeMethods.CFS_CANDIDATEPOS;
lpCandidate.ptCurrentPos = new Point(10, 50);
NativeMethods.ImmSetCandidateWindow(hIMC, ref lpCandidate);
NativeMethods.ImmReleaseContext(this.Handle, hIMC);
break;
case NativeMethods.WM_IME_COMPOSITION:
this.ImeComposition(m);
break;
case NativeMethods.WM_IME_ENDCOMPOSITION:
break;
case NativeMethods.WM_IME_NOTIFY:
switch (m.WParam.ToInt32())
{
case NativeMethods.IMN_OPENCANDIDATE:
// 候補文字ウィンドウが表示された
this.SetCandidateWindowPos(m.HWnd);
break;
case NativeMethods.IMN_CLOSECANDIDATE:
case NativeMethods.IMN_CHANGECANDIDATE:
case NativeMethods.IMN_SETOPENSTATUS:
// 何もしない。
break;
}
break;
}
base.WndProc(ref m);
}
示例13: DisposingWriterThrowsObjectDisposedExceptionWhenUsed
public void DisposingWriterThrowsObjectDisposedExceptionWhenUsed()
{
var writer = new LogWriter(new LoggingConfiguration());
writer.Dispose();
AssertEx.Throws<ObjectDisposedException>(() => writer.Write("Should throw."));
}