本文整理汇总了C#中ILoggerFactory.AddStdio方法的典型用法代码示例。如果您正苦于以下问题:C# ILoggerFactory.AddStdio方法的具体用法?C# ILoggerFactory.AddStdio怎么用?C# ILoggerFactory.AddStdio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILoggerFactory
的用法示例。
在下文中一共展示了ILoggerFactory.AddStdio方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app,
IServiceProvider serviceProvider,
IOmnisharpEnvironment env,
ILoggerFactory loggerFactory,
ISharedTextWriter writer,
IOmnisharpAssemblyLoader loader,
IOptions<OmniSharpOptions> optionsAccessor)
{
Func<RuntimeLibrary, bool> shouldLoad = lib => lib.Dependencies.Any(dep => dep.Name == "OmniSharp.Abstractions" ||
dep.Name == "OmniSharp.Roslyn");
var assemblies = DependencyContext.Default
.RuntimeLibraries
.Where(shouldLoad)
.SelectMany(lib => lib.Assemblies)
.Select(each => loader.Load(each.Name))
.ToList();
PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Value, assemblies);
Workspace = PluginHost.GetExport<OmnisharpWorkspace>();
if (env.TransportType == TransportType.Stdio)
{
loggerFactory.AddStdio(writer, (category, level) => LogFilter(category, level, env));
}
else
{
loggerFactory.AddConsole((category, level) => LogFilter(category, level, env));
}
var logger = loggerFactory.CreateLogger<Startup>();
foreach (var assembly in assemblies)
{
logger.LogDebug($"Loaded {assembly.FullName}");
}
app.UseRequestLogging();
app.UseExceptionHandler("/error");
app.UseMiddleware<EndpointMiddleware>();
app.UseMiddleware<StatusMiddleware>();
app.UseMiddleware<StopServerMiddleware>();
if (env.TransportType == TransportType.Stdio)
{
logger.LogInformation($"Omnisharp server running using {nameof(TransportType.Stdio)} at location '{env.Path}' on host {env.HostPID}.");
}
else
{
logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
}
// ProjectEventForwarder register event to OmnisharpWorkspace during instantiation
PluginHost.GetExport<ProjectEventForwarder>();
// Initialize all the project systems
foreach (var projectSystem in PluginHost.GetExports<IProjectSystem>())
{
try
{
projectSystem.Initalize(Configuration.GetSection(projectSystem.Key));
}
catch (Exception e)
{
var message = $"The project system '{projectSystem.GetType().Name}' threw exception during initialization.\n{e.Message}\n{e.StackTrace}";
// if a project system throws an unhandled exception it should not crash the entire server
logger.LogError(message);
}
}
// Mark the workspace as initialized
Workspace.Initialized = true;
logger.LogInformation("Configuration finished.");
}
示例2: Configure
public void Configure(IApplicationBuilder app,
ILoggerFactory loggerFactory,
IOmnisharpEnvironment env,
ISharedTextWriter writer)
{
Func<string, LogLevel, bool> logFilter = (category, type) =>
(category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase))
&& env.TraceType <= type;
if (env.TransportType == TransportType.Stdio)
{
loggerFactory.AddStdio(writer, logFilter);
}
else
{
loggerFactory.AddConsole(logFilter);
}
var logger = loggerFactory.CreateLogger<Startup>();
app.UseRequestLogging();
app.UseErrorHandler("/error");
app.UseMvc();
if (env.TransportType == TransportType.Stdio)
{
logger.LogInformation($"Omnisharp server running using stdio at location '{env.Path}' on host {env.HostPID}.");
}
else
{
logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
}
// Forward workspace events
app.ApplicationServices.GetRequiredService<ProjectEventForwarder>();
// Initialize everything!
var projectSystems = app.ApplicationServices.GetRequiredServices<IProjectSystem>();
foreach (var projectSystem in projectSystems)
{
try
{
projectSystem.Initalize();
}
catch (Exception e)
{
//if a project system throws an unhandled exception
//it should not crash the entire server
logger.LogError($"The project system '{projectSystem.GetType().Name}' threw an exception.", e);
}
}
// Mark the workspace as initialized
Workspace.Initialized = true;
logger.LogInformation("Solution has finished loading");
}
示例3: Configure
public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider, ILibraryManager manager,
IOmnisharpEnvironment env, ILoggerFactory loggerFactory, ISharedTextWriter writer, IOptions<OmniSharpOptions> optionsAccessor)
{
var assemblies = manager.GetReferencingLibraries("OmniSharp.Abstractions")
.SelectMany(libraryInformation => libraryInformation.LoadableAssemblies)
.Concat(
manager.GetReferencingLibraries("OmniSharp.Roslyn")
.SelectMany(libraryInformation => libraryInformation.LoadableAssemblies)
)
.Select(assemblyName => Assembly.Load(assemblyName));
PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Options, assemblies);
Workspace = PluginHost.GetExport<OmnisharpWorkspace>();
Func<string, LogLevel, bool> logFilter = (category, type) =>
(category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase))
&& env.TraceType <= type;
if (env.TransportType == TransportType.Stdio)
{
loggerFactory.AddStdio(writer, logFilter);
}
else
{
loggerFactory.AddConsole(logFilter);
}
var logger = loggerFactory.CreateLogger<Startup>();
app.UseRequestLogging();
app.UseErrorHandler("/error");
app.UseMiddleware<EndpointMiddleware>();
app.UseMiddleware<StatusMiddleware>();
app.UseMiddleware<StopServerMiddleware>();
if (env.TransportType == TransportType.Stdio)
{
logger.LogInformation($"Omnisharp server running using stdio at location '{env.Path}' on host {env.HostPID}.");
}
else
{
logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
}
// Forward workspace events
PluginHost.GetExport<ProjectEventForwarder>();
foreach (var projectSystem in PluginHost.GetExports<IProjectSystem>())
{
try
{
projectSystem.Initalize(Configuration.GetSubKey(projectSystem.Key));
}
catch (Exception e)
{
//if a project system throws an unhandled exception
//it should not crash the entire server
logger.LogError($"The project system '{projectSystem.GetType().Name}' threw an exception.", e);
}
}
// Mark the workspace as initialized
Workspace.Initialized = true;
logger.LogInformation("Solution has finished loading");
}
示例4: Configure
public void Configure(IApplicationBuilder app,
ILoggerFactory loggerFactory,
IOmnisharpEnvironment env,
ISharedTextWriter writer)
{
Func<string, LogLevel, bool> logFilter = (category, type) =>
(category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase))
&& env.TraceType <= type;
if (env.TransportType == TransportType.Stdio)
{
loggerFactory.AddStdio(writer, logFilter);
}
else
{
loggerFactory.AddConsole(logFilter);
}
var logger = loggerFactory.Create<Startup>();
app.UseRequestLogging();
app.UseErrorHandler("/error");
app.UseMvc();
logger.WriteInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
// Initialize everything!
var projectSystems = app.ApplicationServices.GetRequiredService<IEnumerable<IProjectSystem>>();
foreach (var projectSystem in projectSystems)
{
projectSystem.Initalize();
}
// Mark the workspace as initialized
Workspace.Initialized = true;
// This is temporary so that plugins work
Console.WriteLine("Solution has finished loading");
}