Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
RemoteLogForwarder.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.ServiceModel;
6 
7 using SiliconStudio.Assets.Diagnostics;
8 using SiliconStudio.Core.Diagnostics;
9 
10 namespace SiliconStudio.Assets.CompilerApp
11 {
13  {
14  private readonly ILogger mainLogger;
15  private readonly List<IForwardSerializableLogRemote> remoteLogs = new List<IForwardSerializableLogRemote>();
16 
17  public RemoteLogForwarder(ILogger mainLogger, IEnumerable<string> logPipeNames)
18  {
19  this.mainLogger = mainLogger;
20 
21  foreach (var logPipeName in logPipeNames)
22  {
23  var namedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { SendTimeout = TimeSpan.FromSeconds(300.0) };
24  var remoteLog = ChannelFactory<IForwardSerializableLogRemote>.CreateChannel(namedPipeBinding, new EndpointAddress(logPipeName));
25  remoteLogs.Add(remoteLog);
26  }
27  }
28 
29  public override void Dispose()
30  {
31  foreach (var remoteLog in remoteLogs)
32  {
33  try
34  {
35  // ReSharper disable SuspiciousTypeConversion.Global
36  var channel = remoteLog as ICommunicationObject;
37  // ReSharper restore SuspiciousTypeConversion.Global
38  if (channel != null)
39  channel.Close();
40  }
41  // ReSharper disable EmptyGeneralCatchClause
42  catch { }
43  // ReSharper restore EmptyGeneralCatchClause
44  }
45  }
46 
47  protected override void OnLog(ILogMessage message)
48  {
49  var serializableMessage = message as SerializableLogMessage;
50  if (serializableMessage == null)
51  {
52  var assetMessage = message as AssetLogMessage;
53  if (assetMessage != null)
54  {
55  assetMessage.Module = mainLogger.Module;
56  serializableMessage = new AssetSerializableLogMessage(assetMessage);
57  }
58  else
59  {
60  var logMessage = message as LogMessage;
61  serializableMessage = logMessage != null ? new SerializableLogMessage(logMessage) : null;
62  }
63  }
64 
65  if (serializableMessage == null)
66  {
67  throw new ArgumentException(@"Unable to process the given log message.", "message");
68  }
69 
70  foreach (var remoteLog in remoteLogs)
71  {
72  try
73  {
74  remoteLog.ForwardSerializableLog(serializableMessage);
75  }
76  // ReSharper disable EmptyGeneralCatchClause
77  catch { }
78  // ReSharper restore EmptyGeneralCatchClause
79  }
80  }
81  }
82 }
A class that represents a copy of a LogMessage that can be serialized.
override void OnLog(ILogMessage message)
Called when a log occurred.
A base log message used by the logging infrastructure.
Definition: LogMessage.cs:13
A base class to implement a log listener
Definition: LogListener.cs:10
Provides a specialized LogMessage to give specific information about an asset.
The base interface for log messages used by the logging infrastructure.
Definition: ILogMessage.cs:8
RemoteLogForwarder(ILogger mainLogger, IEnumerable< string > logPipeNames)
override void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
Interface for logging.
Definition: ILogger.cs:8