Repository: litestar-org/litestar

Issue:
Bug: POSTs Result In HTTP 500 When Logging Middleware Enabled
**Describe the bug**
With the logging middleware enabled, POSTs are returning an HTTP 500.

**To Reproduce**
```python
from starlite import Starlite, LoggingConfig, post
from starlite.middleware import LoggingMiddlewareConfig
from pydantic import BaseModel

logging_middleware_config = LoggingMiddlewareConfig()

class Widget(BaseModel):
    name: str
    description: str | None = None
    width_inches: float
    height_inches: float


@post("/")
async def my_handler(data: Widget) -> Widget:
    return data


app = Starlite(
    route_handlers=[my_handler],
    logging_config=LoggingConfig(),
    middleware=[logging_middleware_config.middleware],
)
```

Start up the app, POST to it:

```shell
curl --request POST --url http://localhost:8000/ --header 'Content-Type: application/json' --data '{
  "name": "foo",
  "description": "bar",
  "width_inches": 1.23,
  "height_inches": 4.56
}'
{"status_code":500,"detail":"RuntimeError()"}
```

If I remove the `middleware` argument from the app and restart, POST works as expected.

**Additional context**
Python 3.10.8

```
anyio==3.6.2
appdirs==1.4.4
attrs==22.1.0
bcrypt==4.0.1
beanie==1.15.4
black==22.10.0
casbin==1.17.4
casbin-pymongo-adapter==1.0.0
certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
click==8.1.3
commonmark==0.9.1
coverage==6.5.0
cryptography==38.0.3
distlib==0.3.6
dnspython==2.2.1
email-validator==1.3.0
eradicate==2.1.0
exceptiongroup==1.0.4
Faker==15.3.2
filelock==3.8.0
flake8==5.0.4
flake8-black==0.3.4
flake8-builtins==2.0.1
flake8-comprehensions==3.10.1
flake8-eradicate==1.4.0
flake8-isort==5.0.0
flake8-plugin-utils==1.3.2
flake8-pytest-style==1.6.0
ggshield==1.14.1
graphql-core==3.2.3
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httpcore==0.16.1
httpx==0.23.1
hyperframe==6.0.1
idna==3.4
iniconfig==1.1.1
isort==5.10.1
Jinja2==3.1.2
ldap3==2.9.1
MarkupSafe==2.1.1
marshmallow==3.18.0
marshmallow-dataclass==8.5.10
mccabe==0.7.0
mongomock==4.1.2
mongomock-motor==0.0.13
motor==3.1.1
multidict==6.0.2
mypy-extensions==0.4.3
oauthlib==3.2.2
orjson==3.8.2
packaging==21.3
passlib==1.7.4
pathspec==0.10.2
pep8-naming==0.13.2
picologging==0.9.1
platformdirs==2.5.4
pluggy==1.0.0
pyasn1==0.4.8
pycodestyle==2.9.1
pycparser==2.21
pydantic==1.10.2
pydantic-factories==1.15.0
pydantic-openapi-schema==1.3.0
pyflakes==2.5.0
pygitguardian==1.4.0
Pygments==2.13.0
pymongo==4.3.3
pyparsing==3.0.9
pytest==7.2.0
pytest-asyncio==0.20.2
pytest-cov==4.0.0
python-dateutil==2.8.2
python-dotenv==0.21.0
python-multipart==0.0.5
PyYAML==6.0
requests==2.28.1
rfc3986==1.5.0
rich==12.5.1
sentinels==1.0.0
sgqlc==16.0
simpleeval==0.9.12
six==1.16.0
sniffio==1.3.0
starlite==1.40.1
starlite-multipart==1.2.0
toml==0.10.2
tomli==2.0.1
typing-inspect==0.8.0
typing_extensions==4.4.0
urllib3==1.26.12
uvicorn==0.20.0
virtualenv==20.16.7
yarl==1.8.1
```


Discussion:
I can reproduce the problem. Will take a look into it tonight

Resolving patch:
diff --git a/starlite/middleware/logging.py b/starlite/middleware/logging.py
--- a/starlite/middleware/logging.py
+++ b/starlite/middleware/logging.py
@@ -103,22 +103,26 @@ async def __call__(self, scope: "Scope", receive: "Receive", send: "Send") -> No
         if not hasattr(self, "logger"):
             self.logger = scope["app"].get_logger(self.config.logger_name)
             self.is_struct_logger = structlog_installed and isinstance(self.logger, BindableLogger)
-        if self.config.request_log_fields:
-            await self.log_request(scope=scope)
+
         if self.config.response_log_fields:
             send = self.create_send_wrapper(scope=scope, send=send)
+
+        if self.config.request_log_fields:
+            await self.log_request(scope=scope, receive=receive)
+
         await self.app(scope, receive, send)
 
-    async def log_request(self, scope: "Scope") -> None:
+    async def log_request(self, scope: "Scope", receive: "Receive") -> None:
         """Extract request data and log the message.
 
         Args:
             scope: The ASGI connection scope.
+            receive: ASGI receive callable
 
         Returns:
             None
         """
-        extracted_data = await self.extract_request_data(request=scope["app"].request_class(scope))
+        extracted_data = await self.extract_request_data(request=scope["app"].request_class(scope, receive=receive))
         self.log_message(values=extracted_data)
 
     def log_response(self, scope: "Scope") -> None:


Test patch:
diff --git a/tests/middleware/test_logging_middleware.py b/tests/middleware/test_logging_middleware.py
--- a/tests/middleware/test_logging_middleware.py
+++ b/tests/middleware/test_logging_middleware.py
@@ -1,10 +1,10 @@
 from logging import INFO
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, Dict
 
 import pytest
 from structlog.testing import capture_logs
 
-from starlite import Cookie, LoggingConfig, Response, StructLoggingConfig, get
+from starlite import Cookie, LoggingConfig, Response, StructLoggingConfig, get, post
 from starlite.config.compression import CompressionConfig
 from starlite.config.logging import default_handlers
 from starlite.middleware import LoggingMiddlewareConfig
@@ -143,7 +143,7 @@ def test_logging_middleware_compressed_response_body(include: bool, caplog: "Log
     with create_test_client(
         route_handlers=[handler],
         compression_config=CompressionConfig(backend="gzip", minimum_size=1),
-        middleware=[LoggingMiddlewareConfig(include_compressed_body=include).middleware],
+        middleware=[LoggingMiddlewareConfig(include_compressed_body=include, request_log_fields=[]).middleware],
     ) as client, caplog.at_level(INFO):
         # Set cookies on the client to avoid warnings about per-request cookies.
         client.cookies = {"request-cookie": "abc"}  # type: ignore
@@ -155,3 +155,16 @@ def test_logging_middleware_compressed_response_body(include: bool, caplog: "Log
             assert "body=" in caplog.messages[1]
         else:
             assert "body=" not in caplog.messages[1]
+
+
+def test_logging_middleware_post_body() -> None:
+    @post("/")
+    def post_handler(data: Dict[str, str]) -> Dict[str, str]:
+        return data
+
+    with create_test_client(
+        route_handlers=[post_handler], middleware=[LoggingMiddlewareConfig().middleware], logging_config=LoggingConfig()
+    ) as client:
+        res = client.post("/", json={"foo": "bar"})
+        assert res.status_code == 201
+        assert res.json() == {"foo": "bar"}