Async logging

This commit is contained in:
Westin Miller
2018-11-04 06:33:14 -08:00
parent f1201c6259
commit c2035668cd
2 changed files with 10 additions and 3 deletions

View File

@@ -4,7 +4,7 @@
<variable name="logStamp" value="${time} ${pad:padding=-8:inner=[${level:uppercase=true}]}" /> <variable name="logStamp" value="${time} ${pad:padding=-8:inner=[${level:uppercase=true}]}" />
<variable name="logContent" value="${message:withException=true}"/> <variable name="logContent" value="${message:withException=true}"/>
<targets> <targets async="true">
<target xsi:type="Null" name="null" formatMessage="false" /> <target xsi:type="Null" name="null" formatMessage="false" />
<target xsi:type="File" name="keen" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Keen-${shortdate}.log" /> <target xsi:type="File" name="keen" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Keen-${shortdate}.log" />
<target xsi:type="File" name="main" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Torch-${shortdate}.log" /> <target xsi:type="File" name="main" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Torch-${shortdate}.log" />

View File

@@ -14,6 +14,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using NLog; using NLog;
using NLog.Targets.Wrappers;
using Sandbox; using Sandbox;
using Torch.API; using Torch.API;
using Torch.API.Managers; using Torch.API.Managers;
@@ -57,7 +58,13 @@ namespace Torch.Server
private void AttachConsole() private void AttachConsole()
{ {
var doc = LogManager.Configuration.FindTargetByName<FlowDocumentTarget>("wpf")?.Document; const string target = "wpf";
var doc = LogManager.Configuration.FindTargetByName<FlowDocumentTarget>(target)?.Document;
if (doc == null)
{
var wrapped = LogManager.Configuration.FindTargetByName<WrapperTargetBase>(target);
doc = (wrapped?.WrappedTarget as FlowDocumentTarget)?.Document;
}
ConsoleText.Document = doc ?? new FlowDocument(new Paragraph(new Run("No target!"))); ConsoleText.Document = doc ?? new FlowDocument(new Paragraph(new Run("No target!")));
ConsoleText.TextChanged += (sender, args) => ConsoleText.ScrollToEnd(); ConsoleText.TextChanged += (sender, args) => ConsoleText.ScrollToEnd();
} }