public static HostStub Create(HostArgs hostArgs) { var appDomainSetup = new AppDomainSetup { ApplicationBase = hostArgs.ApplicationBase }; ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(hostArgs.RoleConfigurationFile); appDomainSetup.ConfigurationFile = hostArgs.RoleConfigurationFile; StubManagement.CopyStubAssemblyToRoleDirectory(hostArgs.ApplicationBase); var appDomain = AppDomain.CreateDomain( "LightBlue", null, appDomainSetup); Trace.Listeners.Add(new ConsoleTraceListener()); var stub = (HostStub)appDomain.CreateInstanceAndUnwrap( typeof(HostStub).Assembly.FullName, typeof(HostStub).FullName); stub.ConfigureTracing(new ConsoleTraceShipper()); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionBehaviour.UnhandledExceptionHandler(hostArgs.Title); return(stub); }
private void StartInternal() { ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(_configurationFilePath); CopyStubAssemblyToRoleDirectory(_appDomainSetup.ApplicationBase, _role); _appDomain = AppDomain.CreateDomain("LightBlue", null, _appDomainSetup); _hostStub = (HostStub)_appDomain.CreateInstanceAndUnwrap(typeof(HostStub).Assembly.FullName, typeof(HostStub).FullName); var shipper = new EventTraceShipper(); Action <string> twh = m => _role.TraceWrite(Identifier, m); Action <string> twlh = m => _role.TraceWriteLine(Identifier, m); shipper.TraceWrite += twh; shipper.TraceWriteLine += twlh; _hostStub.ConfigureTracing(shipper); // TODO: decide how this is going to work. _appDomain.UnhandledException += StubExceptionHandler.Handler; try { _started.SetResult(new object()); _role.TraceWriteLine(Identifier, "Role started in app domain: " + _appDomain.Id + " by " + Thread.CurrentThread.Name); _hostStub.Run(_assemblyFilePath, _configurationFilePath, _serviceDefinitionFilePath, _roleName, false); } catch (Exception ex) { _role.TraceWriteLine(Identifier, ex.ToString()); } finally { shipper.TraceWrite -= twh; shipper.TraceWriteLine -= twlh; _completed.SetResult(new object()); } }
public static void PatchWebConfig(WebHostArgs args) { var webConfigFilePath = DetermineWebConfigPath(args.Assembly); if (!File.Exists(webConfigFilePath)) { throw new ArgumentException("No web.config could be located for the site"); } ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(webConfigFilePath); }
public static void Main(string[] args) { var hostArgs = HostArgs.ParseArgs(args); if (hostArgs == null) { return; } var handle = Process.GetCurrentProcess().MainWindowHandle; SetWindowText(handle, hostArgs.Title); var appDomainSetup = new AppDomainSetup { ApplicationBase = hostArgs.ApplicationBase }; ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(hostArgs.RoleConfigurationFile); appDomainSetup.ConfigurationFile = hostArgs.RoleConfigurationFile; StubManagement.CopyStubAssemblyToRoleDirectory(hostArgs.ApplicationBase); var appDomain = AppDomain.CreateDomain( "LightBlue", null, appDomainSetup); Trace.Listeners.Add(new ConsoleTraceListener()); var stub = (HostStub)appDomain.CreateInstanceAndUnwrap( typeof(HostStub).Assembly.FullName, typeof(HostStub).FullName); stub.ConfigureTracing(new ConsoleTraceShipper()); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionBehaviour.UnhandledExceptionHandler(hostArgs.Title); stub.Run(workerRoleAssembly: hostArgs.Assembly, configurationPath: hostArgs.ConfigurationPath, serviceDefinitionPath: hostArgs.ServiceDefinitionPath, roleName: hostArgs.RoleName, useHostedStorage: hostArgs.UseHostedStorage); if (!hostArgs.AllowSilentFail) { throw new InvalidOperationException( string.Format( CultureInfo.InvariantCulture, "The host {0} has exited unexpectedly", hostArgs.Title)); } }
private static void ScrubWebConfigAzureTraceListener(WebHost.Settings settings) { var webConfig = new FileInfo(Path.Combine(settings.SiteDirectory, "web.config")); if (!webConfig.Exists) { throw new FileNotFoundException("Web.config file not found at " + webConfig.FullName); } ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(webConfig.FullName); Trace.TraceInformation("IISExpress removed azure trace listeners from web.config {0}", webConfig.FullName); }
private void StartInternal() { ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(_configurationFilePath); _hostStub = new HostStub2(); if (LogicalCallContextTraceListener.IsInitialized) { throw new InvalidOperationException("There is already a trace listener configured on this logical call context"); } _traceListener = LogicalCallContextTraceListener.Current; Action <string> twh = m => _role.TraceWrite(Identifier, m); Action <string> twlh = m => _role.TraceWriteLine(Identifier, m); _traceListener.TraceWrite += twh; _traceListener.TraceWriteLine += twlh; Trace.Listeners.Add(_traceListener); try { _started.SetResult(new object()); _role.TraceWriteLine(Identifier, "Role started in thread: " + Thread.CurrentThread.ManagedThreadId + " : " + Thread.CurrentThread.Name); _hostStub.Run(_assemblyFilePath, _configurationFilePath, _serviceDefinitionFilePath, _roleName, false); } catch (Exception ex) { _role.TraceWriteLine(Identifier, ex.ToString()); } finally { _traceListener.TraceWrite -= twh; _traceListener.TraceWriteLine -= twlh; _completed.SetResult(new object()); } }