Comments (6)
Anyone watching these issues at all?
from classic.
Hi Brian,
yes, I am watching those, but I am also quite busy with other things ;)
I think I'm missing a bit of context here, and I'm not 100% sure what it is you are trying to achieve
Can you confirm that you are indeed using ASP.NET MVC ?
I don't think I understand what it is you are trying to do with
"WriteTo": [
// ...
{
"Name": "Mvc"
},
// ...
],
this would map in code to a configuration like .WriteTo.Mvc()
... and indeed, as the error says, there is no such thing : Unable to find a method called Mvc
.
Also, note that by default, the HttpModule
writes to the global static Log.Logger
instance, so this is the one you need to configure properly, or alternatively, you can tell the HttpModule
to which instance of Logger
to write to.
To use the default global logger, this means you should be doing something like
// configuration / creation of a logger
// _logger = new LoggerConfiguration()
// .xxxx()
// .CreateLogger();
// make it the default global logger
Log.Logger = _logger ;
or you can do this, as seen in the README
:
SerilogWebClassic.Configure(cfg => cfg
.UseLogger(_logger )
));
I hope this helps !
from classic.
Yes, this is a classic asp.net mvc app. The issue is that no http requests are being logged out.
The last part about configuring the global logger or the .UseLogger configuration method isn't mentioned in the README as a requirement to enable request logging output. That being said, I added both and yet I am not seeing any request logs being output. Here is my updated setup and settings. At the end I included the log output to show that the logger is correctly logging to the file output as I expect but I don't get any request logs when navigating around the web app.
So my real question is: Is there anyway to debug that the actual ApplicationLifecycleModule
HttpModule is loaded and configured properly?
Application_Start
var environmentName = (Environment.GetEnvironmentVariable("ASPNET_ENVIRONMENT") ??
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ??
DefaultEnvironmentName).ToLower();
Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
// Configure from serilog json configuration
var configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile($"serilog.{environmentName}.json")
.Build();
// Manual code configuration
_logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
// Set the global logger
Log.Logger = _logger;
// Should be enabled by default but adding this to ensure it is true
SerilogWebClassic.Configure(cfg => cfg
.UseLogger(_logger)
.LogAtLevel(LogEventLevel.Verbose)
.EnableFormDataLogging()
);
_logger.Information("Application Start");
_logger.Information("----IS THIS LOGGING----");
Serilog.development.json
{
"Serilog": {
"Using": "SerilogWeb.Classic.Mvc",
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "Debug"
},
{
"Name": "File",
"Args": {
"path": "%PROGRAMDATA%\\logs\\Log.txt",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
],
"Enrich": [
"FromLogContext",
"WithMachineName",
"WithThreadId"
],
"Properties": {
"Application": "MyApplication",
"Environment": "Development"
}
}
}
Log Output
{"@t":"2020-11-02T16:49:50.9885754Z","@m":"Application Start","@i":"41091c09","MachineName":"blahblah","ThreadId":47,"Application":"MyApplication","Environment":"Development"}
{"@t":"2020-11-02T16:49:51.0115770Z","@m":"----IS THIS LOGGING----","@i":"9e8e5ea3","MachineName":"blahblah","ThreadId":47,"Application":"MyApplication","Environment":"Development"}
EDIT:
I found how to view the loaded HttpModules. Here is a screenshot that shows the module is loaded properly.
from classic.
Update
Okay, I honestly don't know what is going on, but seemingly without change, it simply started logging requests. The only explanation I can think of is that Rebuilding and restarting my IIS site still somehow wasn't running updated binaries. It started working once I went into Modules and decompiled and loaded the Serilog.Classic symbols with resharper and debugged into the HttpModule. Which I guess means you can close this issue. Now I just have to figure out why its double logging the requests.
from classic.
The last part about configuring the global logger or the .UseLogger configuration method isn't mentioned in the README as a requirement to enable request logging output.
It is there in a sample, but maybe not as visible as it should be. Pull Requests are welcome :)
When trying to figure out issues, I found that it usually helps to :
- go back to writing all the Serilog configuration code in C# instead of loading from the settings first.
- use a "simpler" Sink like the console one to validate that entries are indeed written (with the file ones, there are many reasons why things would not go according to plan, like permissions, disk issues etc etc)
And only once you have confirmed that it works, move it to configuration file (although in my opinion, you usually only need a minor part of the configuration to be settable through the config file. In your example, for instance, I believe the enrichment FromLogContext
and WithMachineName
might as well be configured in C# code.
Not sure this is related at all, but from the code samples you posted, I see :
SerilogWebClassic.Configure(cfg => cfg
.UseLogger(_logger)
.LogAtLevel(LogEventLevel.Verbose)
.EnableFormDataLogging()
);
.LogAtLevel(LogEventLevel.Verbose)
means that log entries for http requests will be logged at the level Verbose
(i.e. the lowest level available) ...
but your Logger is configured with "MinimumLevel": "Information"
, meaning entries of levels lower than Information
will be completely ignored. This would explain why you do not observe any entries in your log file ?
from classic.
Okay, I honestly don't know what is going on, but seemingly without change, it simply started logging requests. The only explanation I can think of is that Rebuilding and restarting my IIS site still somehow wasn't running updated binaries. It started working once I went into Modules and decompiled and loaded the Serilog.Classic symbols with resharper and debugged into the HttpModule. Which I guess means you can close this issue. Now I just have to figure out why its double logging the requests.
I think I've had issues in the past, about IIS aggressively caching some Http modules, and not seeing changes until I actively tried to clean up that cache. Things I remember doing back in the days was deleting file in each of the "Temporary ASP.NET files" folder of each variant of each installed version of .NET (x86 and x64) ... glorious times 🤕
I'll close this issue for now, as I believe you could solve the part related to Serilog.
from classic.
Related Issues (20)
- Calling cfg.LogAtLevel to set the LogEventLevel seems to disable HTTP request logging? HOT 8
- UserName enricher shows (anonymous) in ApplicationLifecycleModule with Microsoft.AspNet.WebApi.* >= 5.2.5 HOT 5
- Applicationlifecycle module question HOT 7
- Using the EnvironmentUserName if none? HOT 2
- HttpModule stops working when stressed. HOT 6
- Exception with null key in form data HOT 3
- EnableFormDataLogging not logging anything with WebApi HOT 2
- .netStandard v2 version ? HOT 1
- HttpRequestUrlEnricher gives "Request is not available in this context" exception HOT 6
- Special cases when using `FilterKeywords()` with `EnableFormDataLogging()` HOT 5
- ASP .NET Core enrichers? HOT 2
- Add Http Data To All Logging Events HOT 1
- WithUserName Only Working With HttpModule Logging But Doesnt Log During Web Service/API Logs HOT 8
- HttpModule isn't extensible? HOT 2
- SerilogWeb.Classic IIS classic mode incompatibility HOT 1
- Customize HttpRequestEventMessageTemplate HOT 6
- Log CorrelationId with SerilogWeb.Classic's log entries HOT 2
- IIS Web application hang up after multiple requests stuck on "Begin request" HOT 1
- Multiple log messages for single Request with error 404 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from classic.