public void Test1() { var logger = LogManager.GetLogger("Aaa"); var target = new LogReceiverWebServiceTarget(); target.EndpointAddress = "http://notimportant:9999/"; target.Parameters.Add(new MethodCallParameter("message", "${message}")); target.Parameters.Add(new MethodCallParameter("date", "${longdate}")); SimpleConfigurator.ConfigureForTargetLogging(target); logger.Info("aa"); }
/// <summary> /// Configures the logging and tracing using the given controller configuration. /// </summary> /// <param name="controllerConfiguration">The controller configuration.</param> public static void Configure(ControllerConfiguration controllerConfiguration) { // we better do this on the UI thread if (!Deployment.Current.Dispatcher.CheckAccess()) { Deployment.Current.Dispatcher.BeginInvoke(() => Configure(controllerConfiguration)); return; } // check if tracing should be enabled if (controllerConfiguration.EnableTracing && !string.IsNullOrEmpty(controllerConfiguration.TracingEndpointAddress)) { // create the configuration var loggingConfig = new LoggingConfiguration(); // create the target var serviceTarget = new LogReceiverWebServiceTarget(); serviceTarget.ClientId = "WP7"; serviceTarget.Name = "WebServiceTarget"; serviceTarget.IncludeEventProperties = true; serviceTarget.UseBinaryEncoding = false; serviceTarget.EndpointAddress = controllerConfiguration.TracingEndpointAddress; // add parameters var parameter = new MethodCallParameter("time", "${time}"); serviceTarget.Parameters.Add(parameter); parameter = new MethodCallParameter("threadid", "${threadid}"); serviceTarget.Parameters.Add(parameter); // create the only rule var rule = new LoggingRule("*", LogLevel.Trace, serviceTarget); loggingConfig.LoggingRules.Add(rule); // set the config LogManager.Configuration = loggingConfig; } else { // turn off logging if (LogManager.Configuration != null && LogManager.Configuration.LoggingRules != null) { LogManager.Configuration.LoggingRules.Clear(); LogManager.ReconfigExistingLoggers(); } } }
public App() { this.Startup += this.Application_Startup; this.Exit += this.Application_Exit; this.UnhandledException += this.Application_UnhandledException; InitializeComponent(); LogManager.ThrowExceptions = true; var target = new LogReceiverWebServiceTarget(); target.EndpointAddress = new Uri(HtmlPage.Document.DocumentUri, "NLogReceiver.svc").ToString(); target.Parameters.Add(new MethodCallParameter("message", "${message}")); target.Parameters.Add(new MethodCallParameter("date", "${longdate}")); var buffer = new BufferingTargetWrapper(target) { BufferSize = 10, FlushTimeout = 1000 }; SimpleConfigurator.ConfigureForTargetLogging(buffer); }
/// <summary> /// Configures NLog's logging with the given information. /// </summary> /// <param name="enableTracing">If set to <c>true</c> enables NLog's logging at "Trace" level. If set to <c>false</c> disables logging.</param> /// <param name="tracingEndpointAddress">The endpoint address of the WCF service that receives tracing messages.</param> public static void Configure(bool enableTracing, string tracingEndpointAddress) { // check if tracing should be enabled if (enableTracing && !string.IsNullOrEmpty(tracingEndpointAddress)) { // create the configuration var loggingConfig = new LoggingConfiguration(); // create the target var serviceTarget = new LogReceiverWebServiceTarget(); serviceTarget.ClientId = "PC"; serviceTarget.Name = "WebServiceTarget"; serviceTarget.IncludeEventProperties = true; serviceTarget.UseBinaryEncoding = false; serviceTarget.EndpointAddress = tracingEndpointAddress; // add parameters var parameter = new MethodCallParameter("time", "${time}"); serviceTarget.Parameters.Add(parameter); parameter = new MethodCallParameter("threadid", "${threadid}"); serviceTarget.Parameters.Add(parameter); // create the only rule var rule = new LoggingRule("*", LogLevel.Trace, serviceTarget); loggingConfig.LoggingRules.Add(rule); // set the config LogManager.Configuration = loggingConfig; } else { if (LogManager.Configuration != null && LogManager.Configuration.LoggingRules != null) { LogManager.Configuration.LoggingRules.Clear(); LogManager.ReconfigExistingLoggers(); } } }