本文整理汇总了C#中ObservableEventListener.LogToFlatFile方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableEventListener.LogToFlatFile方法的具体用法?C# ObservableEventListener.LogToFlatFile怎么用?C# ObservableEventListener.LogToFlatFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableEventListener
的用法示例。
在下文中一共展示了ObservableEventListener.LogToFlatFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterEFLogger
private static void RegisterEFLogger()
{
var listener = new ObservableEventListener();
listener.EnableEvents(EFLogging.Logger, EventLevel.LogAlways, Keywords.All);
listener.LogToFlatFile("EFSqls.log");
listener.LogToWindowsAzureTable(instanceName: "Protiviti", connectionString: "UseDevelopmentStorage=true",tableAddress:"EFSqls");
}
示例2: RegisterLogger
private static void RegisterLogger()
{
var listener = new ObservableEventListener();
listener.EnableEvents(WebApiTracing.Log, EventLevel.LogAlways, Keywords.All);
listener.LogToConsole();
listener.LogToFlatFile("test.log");
listener.LogToWindowsAzureTable(instanceName: "Protiviti", connectionString: "UseDevelopmentStorage=true");
}
示例3: ConfigureLogging
private void ConfigureLogging()
{
eventListener = new ObservableEventListener();
eventListener.EnableEvents(SparkEngineEventSource.Log, EventLevel.LogAlways,
Keywords.All);
eventListener.EnableEvents(SparkMongoEventSource.Log, EventLevel.LogAlways,
Keywords.All);
eventListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.LogAlways, Keywords.All);
var formatter = new JsonEventTextFormatter(EventTextFormatting.Indented);
eventListener.LogToFlatFile(@"C:\projects\fhir\log\spark.log", formatter);
}
示例4: Application_Start
protected void Application_Start()
{
var listener = new ObservableEventListener();
listener.EnableEvents(WebApiTracing.Log, EventLevel.LogAlways, Keywords.All);
listener.LogToFlatFile("test.log");
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
示例5: Configure
public static void Configure()
{
List<EventSource> eventSources = new List<EventSource>(new[] { DomainEventSource.Log });
ObservableEventListener logListner = new ObservableEventListener();
foreach (var eventSource in eventSources)
{
logListner.EnableEvents(eventSource, EventLevel.Error , Keywords.All);
}
logListner.LogToFlatFile("log.txt");
}
示例6: RegisterLoggingSources
public static void RegisterLoggingSources(IEnumerable<EventSource> logSources, ISiteSettings settings)
{
var logListener = new ObservableEventListener();
foreach (var logSource in logSources)
{
logListener.EnableEvents(
logSource, EventLevel.LogAlways, Keywords.All);
}
logListener.LogToFlatFile(
fileName: settings.LogFilePath,
formatter: new EventTextFormatter());
}
示例7: Configure
public static void Configure()
{
List<EventSource> eventSources = new List<EventSource>() { DomainEventSource.Log, SiteEventSource.Log };
ObservableEventListener logListener = new ObservableEventListener();
foreach (var eventSource in eventSources)
{
logListener.EnableEvents(eventSource, EventLevel.LogAlways, Keywords.All);
}
logListener.LogToFlatFile("./Log.txt");
}
示例8: WhenFileNameIsNull
public void WhenFileNameIsNull()
{
try
{
var formatter = new EventTextFormatter(EventTextFormatter.DashSeparator);
using (var listener = new ObservableEventListener())
{
listener.LogToFlatFile(null, formatter);
}
}
catch (ArgumentNullException ex)
{
Assert.AreEqual("Value cannot be null.\r\nParameter name: fileName", ex.Message);
}
}
示例9: EventWithPayloadAndEnumsInXml
public void EventWithPayloadAndEnumsInXml()
{
string fileName = "LogUsingPayloadWithEnumsInProc";
File.Delete(fileName);
var formatter = new XmlEventTextFormatter(EventTextFormatting.Indented, "d");
var logger = MockEventSourceInProcEnum.Logger;
using (var listener = new ObservableEventListener())
{
listener.EnableEvents(logger, EventLevel.LogAlways, Keywords.All);
listener.LogToFlatFile(fileName, formatter);
try
{
logger.SendEnumsEvent16(MockEventSourceInProcEnum.MyColor.Green, MockEventSourceInProcEnum.MyFlags.Flag1);
}
finally
{
listener.DisableEvents(logger);
}
}
var rawOutput = FlatFileHelper.GetAllText(fileName);
var entries = XDocument.Parse("<Events>" + rawOutput + "</Events>").Root.Elements();
Assert.AreEqual(1, entries.Count());
XmlFormattedEntry.Fill(entries.First());
Assert.AreEqual("a", XmlFormattedEntry.Payload.Elements().First().Attribute("Name").Value);
Assert.AreEqual("2", XmlFormattedEntry.Payload.Elements().First().Value);
Assert.AreEqual("b", XmlFormattedEntry.Payload.Elements().Last().Attribute("Name").Value);
Assert.AreEqual("1", XmlFormattedEntry.Payload.Elements().Last().Value);
}
示例10: CreateListener
/// <summary>
/// Creates an event listener that logs using a <see cref="FlatFileSink"/>.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <param name="formatter">The formatter.</param>
/// <param name="isAsync">Specifies if the writing should be done asynchronously, or synchronously with a blocking call.</param>
/// <returns>An event listener that uses <see cref="FlatFileSink"/> to log events.</returns>
public static EventListener CreateListener(string fileName = null, IEventTextFormatter formatter = null, bool isAsync = false)
{
var listener = new ObservableEventListener();
listener.LogToFlatFile(fileName, formatter, isAsync);
return listener;
}
示例11: MultipleEventListenersLevel
static void MultipleEventListenersLevel()
{
// Set up and enable the event listeners - typically done when the application starts
var listener1 = new ObservableEventListener();
var listener2 = new ObservableEventListener();
listener1.EnableEvents(MyCompanyEventSource.Log, EventLevel.Error, Keywords.All);
listener2.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);
listener1.LogToConsole();
var subscription = listener2.LogToFlatFile(@"C:\Temp\DemoSemanticLogging.log", new EventTextFormatter("===================", "==================="));
// Log some messages
MyCompanyEventSource.Log.Startup();
MyCompanyEventSource.Log.Failure("Couldn't connect to server.");
Console.WriteLine("Written two log messages.\nUsing a basic console listener and a Flat File listener to capture them.");
Console.WriteLine("Only the critical message appears in the console, both appear in: \nC:\\Temp\\DemoSemanticLogging.log.\n");
// Flush the sink
subscription.Sink.FlushAsync().Wait();
// Disable the event listener - typically done when the application terminates
listener1.DisableEvents(MyCompanyEventSource.Log);
listener2.DisableEvents(MyCompanyEventSource.Log);
listener1.Dispose();
listener2.Dispose();
}
示例12: WhenFileNameIsFolder
public void WhenFileNameIsFolder()
{
try
{
var formatter = new EventTextFormatter(EventTextFormatter.DashSeparator);
using (var listener = new ObservableEventListener())
{
listener.LogToFlatFile(".", formatter);
}
}
catch (ArgumentException ex)
{
Assert.AreEqual("A file name with a relative path is not allowed. Provide only the file name or the full path of the file.", ex.Message);
}
}
示例13: WhenInvalidCharactersInFileName1
public void WhenInvalidCharactersInFileName1()
{
try
{
var formatter = new EventTextFormatter(EventTextFormatter.DashSeparator);
using (var listener = new ObservableEventListener())
{
listener.LogToFlatFile(@"|", formatter);
}
}
catch (ArgumentException ex)
{
Assert.AreEqual("Illegal characters in path.", ex.Message);
}
}
示例14: WhenFileNameIsEmpty
public void WhenFileNameIsEmpty()
{
try
{
var formatter = new EventTextFormatter(EventTextFormatter.DashSeparator);
using (var listener = new ObservableEventListener())
{
listener.LogToFlatFile(string.Empty, formatter);
}
}
catch (ArgumentException ex)
{
Assert.AreEqual("Argument is empty\r\nParameter name: fileName", ex.Message);
}
}
示例15: WhenFilePathLengthExceedsMaxExceptionOccursEarly
public void WhenFilePathLengthExceedsMaxExceptionOccursEarly()
{
try
{
var folderName = "a";
string completePath = string.Empty;
int countLength = Directory.GetCurrentDirectory().Length;
int folderNameLength = 246 - countLength;
for (int l = 1; l < folderNameLength; l++)
{
folderName = folderName + "a";
}
completePath = DeleteFolder(folderName);
Directory.CreateDirectory(completePath);
var fileName = "longpath.log";
var folderfilePath = completePath + "\\" + fileName;
var formatter = new EventTextFormatter(EventTextFormatter.DashSeparator);
using (var listener = new ObservableEventListener())
{
listener.LogToFlatFile(folderfilePath, formatter);
}
Assert.IsFalse(File.Exists(folderfilePath));
}
catch (PathTooLongException ex)
{
Assert.AreEqual(ex.Message, "The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.");
}
}