简体   繁体   中英

ASP.NET Core EventLog Not Registering

I've been trying to add an EventLog Provider for logging in my ASP.NET Application. I was able to add it to the 'Application' source, but there's a lot of information in that log and I'd like for it to be under it's own source. I've actually gotten 3 logs to be written to it's own source, but I have no idea how or why. This is what my code looks like right now:

CreateWebHostBuilder(args)
            .ConfigureLogging( logging =>
            {


                logging.AddEventLog(
                    new Microsoft.Extensions.Logging.EventLog.EventLogSettings
                    {
                        SourceName = "MySweetApp",
                        MachineName = ".",
                        LogName = "MySweetApp",
                        Filter = (category, level) =>
                        {
                            if (category.EndsWith("Controller") || level >= LogLevel.Error)
                            {
                                return true;
                            }
                            return false;
                        },
                    });
            })
            .Build()
            .Run();

I've already added a registry key there for this app (since the app doesn't have admin rights and can't add a source) along with the EventMessageFile of C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\EventLogMessages.dll . I've messed with different values of this including the non-64 framework folder and other v2 versions. There are no errors or warnings, and I can't find any logs that have anything related in them. I've also added a debug logger with .AddDebug() and it prints just fine the debug window.

I'm guessing it's something on the server side of things and not my code. Thanks in advance.

UPDATE: I can now re-create my app creating error logs in the eventlog. If I start my program by double-clicking the .exe, there is an authentication error that is thrown and gets sent to the log.

Found it. I still had a "Logging" section of my appsettings.json that was set default to warning. Deleted that section and everything started printing!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM