Skip to content

EventLog should support directory generation #42475

@taori

Description

@taori

Is your feature request related to a problem? Please describe.

I began developing a worker service and want to utilize AddEventLog in my logging configuration - Unfortunately i can't seem to find a way to configure my event logging in a way where the eventlog that is generated results in a nested structure (using folders in

eventvwr -> "applications and service programs" -> AMU -> MyEventLog
instead of
eventvwr -> "applications and service programs" -> AMU/MyEventLog

Describe the solution you'd like

Ideally instead of EventSource creation to fail if i pick AMU\MyEventLog it would generate a folder structure instead.

Describe alternatives you've considered

A custom event log provider would work obviously, but this functionality should be available to everyone.

Additional context

namespace LaunchProcessInCurrentUserService
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // see https://web.archive.org/web/20200423120541/https://csharp.christiannagel.com/2019/10/15/windowsservice/
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseWindowsService()
                .ConfigureLogging(builder =>
                {
                    builder.AddFilter<EventLogLoggerProvider>(level => level >= LogLevel.Information);
                })
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddLogging(configure =>
                    {
                        configure.AddEventLog();
                        configure.AddDebug();
                        if (hostContext.HostingEnvironment.IsDevelopment())
                        {
                            configure.AddConsole();
                        }
                    });
                    
                    services.AddHostedService<Worker>()
                        .Configure<EventLogSettings>(els =>
                        {
                            els.LogName = hostContext.Configuration.GetValue<string>("Application:EventLogApplicationName") ?? "CurrentUserService";
                            els.SourceName = hostContext.Configuration.GetValue<string>("Application:EventLogSource") ?? "CurrentUserService Source";
                        });
                });
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions